﻿
#UseHook
#InstallKeybdHook
#InstallMouseHook

#HotkeyInterval 1000  ; 这是默认值 (时间定位).
#MaxHotkeysPerInterval 150
#WinActivateForce 
;;;这个似乎说是能解决激活时只是闪耀而不置于最前的问题
DetectHiddenWindows, On







^MButton up::

clipboard = ; 清空剪贴板 20171027加入
send, ^c
ClipWait  ; 等待剪贴板中出现文本.
clipboard = %clipboard%   ; 把任何复制的文件, HTML 或其他格式的文本转换为纯文本.
;~ MsgBox %clipboard% 
;~ Sleep, 200
Send, {F3}
;clipboard = ; 清空剪贴板 20171027加入
return




alt & r::

ToolTip, Reloading...
Sleep, 800
ToolTip
Reload
return




/* ;把输入法转换和(激发函数签名, 都放在a输入法这个ahk里, 
shift::
SetCapsLockState, off
;SwitchIME2("00000804") ;在win7下面貌似这个00000804是ch英文输入法,但在xp和win8下面貌似00000409才行
SwitchIME2("00000409")
;PostMessage, 0x50, 0, 0x4090409,, A ;貌似这个更快更有效
return


shift & Space::
SetCapsLockState, off
SwitchIME2("00000409")
;send, ^+1
SwitchIME2("00000804")
return


CapsLock::
SwitchIME2("00000409")
SetCapsLockState, on
return
*/

SwitchIME2(dwLayout) ;my function
{
HKL:=DllCall("LoadKeyboardLayout", Str, dwLayout, UInt, 1)
ControlGetFocus,ctl,A
SendMessage,0x50,0,HKL,%ctl%,A
}



+Down:: 
;171107, 发现用!Down, 会导致在excel里只要按下enter, 就会自动复制粘贴板内容, 非常怪, 
;以后要重视这个问题, 不能用!alt了
winget, nowPN, ProcessName, A
if (nowPN = "EXCEL.EXE")
{
		;send, {Esc}
		send, {Down}
		send, ^v
	}
	
return



ctrl & F1::
;msgbox 开始

	IfWinExist, ~bb
	{
			loop
			{
			WinActivate, ~bb
			wingettitle, itstitle, A
			
			
			}until (itstitle = "~bb")
		sleep 600
		send !{F4}	
	}
sleep, 300


	IfWinExist, ~trans
	{
			loop
			{
			WinActivate, ~trans
			wingettitle, itstitle, A
			
			
			}until (itstitle = "~trans")
		sleep 600
		send !{F4}	
	}
sleep, 300


filemove, C:\Users\flx\Desktop\~bb\*.pdf, C:\Users\flx\Desktop\~trans\*.pdf
filedelete, C:\Users\flx\Desktop\temp01.pdf


run C:\working doc\software\PDF 权限破解\pwdremover\winDecrypt.exe

winwaitactive, PDF Password Remover v3.0, , 1
;sleep, 1600
Loop   ;;;使用颜色巧妙解决判断是否运行完成，这里判断是否已打开软件
{
sleep, 300
PixelGetColor, itscolor, 500, 12, RGB  ;;右边蓝色按钮
	if (itscolor = "0x6B7D94")
	{
		break
	}
}

MouseClick, left, 55,320
;sleep, 1500
Loop   ;;;使用颜色巧妙解决判断是否运行完成，这里判断是否已打开选择文件界面
{
sleep, 300
PixelGetColor, itscolor, 759, 12, RGB  ;;右边蓝色按钮
	if (itscolor = "0x6B7D94")
	{
		break
	}
}


;MouseClick, left, 60,151  ;;这个是点击桌面
;	sleep, 800
;	send ~trans\
;	sleep, 800
;	send {enter}
;sleep, 1000
;controlsettext, Edit1, C:\Users\flx\Desktop\~trans, A 
;send !o
sleep, 200
MouseClick, left, 300,200  ;;点击空白地区
send ^a
sleep 800



send !o
;msgbox WHY-1
;sleep, 2500
Loop   ;;;使用颜色巧妙解决判断是否运行完成的问题
{
sleep, 300
PixelGetColor, itscolor, 339, 11, RGB   ;;右顶端小蓝色
	if (itscolor = "0x637994")
	{
		break
	}
}





;MouseClick, left, 301,242  ;;这个是点击下拉箭头
;;sleep, 500
;Loop   ;;;使用颜色巧妙解决判断是否运行完成的问题，这里判断是否出现选择文件夹界面，并且看看按钮可用
;{
;sleep, 200
;PixelGetColor, itscolor, 303, 238, RGB
;	if (itscolor = "0xB57552")
;	{
;		break
;	}
;}

;MouseClick, left, 301,242  ;;这个是点击下拉箭头
;	;send C:\Users\flx\Desktop\
;	;sleep, 1500
;	;send {enter}
;;sleep 1500
;Loop   ;;;使用颜色巧妙解决判断是否运行完成的问题，这里判断是否出现选择文件夹界面，并且看看按钮可用
;{
;sleep, 200
;PixelGetColor, itscolor, 303, 238, RGB
;	if (itscolor = "0xB57552")
;	{
;		break
;	}
;}


MouseClick, left, 351,333  ;;这个是点击下拉框了
sleep, 200
MouseClick, left, 351,333  ;;这个是点击下拉框了
sleep, 200
MouseClick, left, 351,333  ;;这个是点击下拉框了
sleep, 200
MouseClick, left, 351,333  ;;这个是点击下拉框了
sleep, 200


;send %itsname%
MouseClick, left, 85,334  ;;这个是点击~trans文件夹
sleep 800
MouseClick, left, 219,407  ;;这个是点击确定
;msgbox WHY0

Loop   ;;;使用颜色巧妙解决判断是否运行完成的问题
{
sleep, 300
PixelGetColor, itscolor, 23, 362, RGB
	if (itscolor = "0xD6D7CE")
	{
		break
	}
}
;sleep 5000

send !{F4}
sleep 800


run, C:\Program Files\PDFBinder\PDFBinder.exe
Loop ;使用鼠标下的control判断是否激活，
{
sleep, 1
	mousemove, 52, 41
	mousegetpos, , , id, nowcontrol
	if (nowcontrol = "WindowsForms10.Window.8.app.0.33c0d9d1" or nowcontrol = "WindowsForms10.Window.8.app.0.378734a1")
	{
		break
	}
}
mouseclick, , 52, 41 ;点击add文件
;msgbox yes

Loop ;使用鼠标下的control判断是否激活，然后点桌面
{
sleep, 1
	mousemove, 236, 142
	mousegetpos, , , id, nowcontrol
	if (nowcontrol = "DirectUIHWND2")
	{
		break
	}
}

;msgbox why
mouseclick, , 236, 142
sleep, 100
;tooltip, %nowcontrol%

controlfocus, Edit1, A
controlsettext, Edit1, C:\Users\flx\Desktop\~trans, A
;tooltip, no
sleep, 100
send, {enter}
sleep, 200
mouseclick, , 236, 142 ;tmd不点一下进去不能全选啊
sleep, 200

send, ^a
sleep, 300
send, {enter}

sleep, 300

Loop ;使用鼠标下的control判断是否激活，
{
sleep, 1
	mousemove, 208, 43
	mousegetpos, , , id, nowcontrol
	if (nowcontrol = "WindowsForms10.Window.8.app.0.33c0d9d1" or nowcontrol = "WindowsForms10.Window.8.app.0.378734a1")
	{
		break
	}
}
mouseclick, , 208, 43 ;点击blind按钮


Loop ;使用鼠标下的control判断是否激活，然后点桌面
{
sleep, 1
	mousemove, 236, 142
	mousegetpos, , , id, nowcontrol
	if (nowcontrol = "DirectUIHWND2")
	{
		break
	}
}
;mouseclick, , 55, 155
sleep, 100

controlsettext, Edit1, C:\Users\flx\Desktop\temp01.pdf, A
sleep, 200
send, {enter}
sleep, 200
;;然后之后好像它会自动打开合并后的pdf


;~ send, !{F4}
;~ sleep, 1000
;~ run, C:\Users\flx\Desktop\~trans\temp01.pdf
;~ ;sleep, 2000
;~ Loop   ;;;使用颜色巧妙解决判断是否运行完成，这里判断已经成功打开pdf
;~ {
;~ sleep, 300
;~ PixelGetColor, itscolor, 81, 264, RGB
	;~ if (itscolor = "0xFFFFFF")
	;~ {
		;~ break
	;~ }
;~ }

Loop ;使用鼠标下的control判断是否激活伏羲pdf浏览，
{
sleep, 1
	mousemove, 700, 500
	mousegetpos, , , id, nowcontrol
	wingettitle, nowtitle, ahk_id %id%
	tooltip, %nowtitle%
	if (instr(nowtitle, "福昕") > 0)
	{
		break
	}
}
sleep, 100
mouseclick, , 700, 500
sleep, 100



clipboard = ;:= "" ;似乎官网说清除黏贴板, 用的是 clipboard = ; 就完了, 而不是:= ""
send, ^a
Loop   ;;;使用颜色巧妙解决判断是否运行完成的问题，这里是判断是否全选完成
{
	
sleep, 100

;PixelGetColor, itscolor, 1213, 917, RGB
;wingetclass, itsclass, A
;	if (itscolor = "0xFFFFFF" and itsclass = "classFoxitReader")
PixelGetColor, itscolor1, 354, 406, RGB
PixelGetColor, itscolor2, 414, 440, RGB
wingetclass, itsclass, A
	if ((itscolor1 = "0xB0CFE2" or itscolor2 = "0xB0CFE2") and itsclass = "classFoxitReader")
	{
		break
	}else
	{
		send, ^a
		sleep, 1000
	}
}
sleep, 200



Loop
{
clipboard = ; 清空剪贴板 ;20171027加入
send, ^c
sleep, 1000 + 500 * A_Index
	if (clipboard <> "")
	{
	break	
	}else
	{
		sleep, % 500 * a_INDEX
	}
}
;send, !{F4}
;winclose, temp01.pdf - 福昕阅读器 - [temp01.pdf]
winclose, temp01.pdf - 福昕阅读器
sleep, 200
winclose, PDFBinder
sleep, 200





			WinGet, id, list,,, Program Manager
			Loop, %id%
			{
				this_id := id%A_Index%
				WinGetTitle, this_title, ahk_id %this_id% 
				targettext = CONTAINER RELEASE
				;StringGetPos, pos, this_title, %targettext%
				pos := InStr(this_title, targettext)
				if (pos > 0)
				{
					;MsgBox, The string was found at position %pos%.
					WinActivate, ahk_id %this_id%
					;msgbox yes
				}
			}
			
			loop
			{
				wingettitle, itstitle, A
				checkactive := instr(itstitle, targettext)
				if (checkactive = 0)
				{
					sleep, 400
					WinActivate, ahk_id %this_id%
				}else
				{
					break
				}
				
			}
			
sleep, 1000
mouseclick, ,156, 827
sleep, 1500
mouseclick, ,943, 437


Loop
{
mousegetpos, posx ,posy
tooltip, waiting...
sleep, 100
wingettext, itstext, A
checkfinish := instr(itstext, "成功导入")
	if (checkfinish > 0)
	{
		tooltip
		msgbox 可以删除了
		filedelete, C:\Users\flx\Desktop\~trans\*.pdf		
		break
	}
}

clipboard = ; 清空剪贴板 20171027加入

return




Alt & m::


	gosub showmdict

	SetCapsLockState, off
	SwitchIME2("00000409")
	

return



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

showmdict:        ;;;;用于弹出mdict词典

IfWinExist, ahk_class MDictMainWnd
{
WinShow, ahk_class MDictMainWnd
WinActivate, ahk_class MDictMainWnd
}else
{
	run %mdictpath%
	;mywc("MDictMainWnd", "ahk_class MDictMainWnd")
	WinShow, ahk_class MDictMainWnd
	WinActivate, ahk_class MDictMainWnd
}
send, {Enter}

return 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
^Numpad8::

MouseGetPos, xpos, ypos 
		;Msgbox, The cursor is at X%xpos% Y%ypos%. 
PixelGetColor, itscolor, %xpos%, %ypos%, RGB

		; This example allows you to move the mouse around to see
		; the title of the window currently under the cursor:
#Persistent
SetTimer, WatchCursor, 100  ;;;;settimer函数，表示每100时间定位运行watchcusror函数一次
return

WatchCursor:   ;;;注意，这样表示，表示下面的直到return是一个函数，可以引用到其他代码中去，好！
MouseGetPos, xpos, ypos 
MouseGetPos, , , id, control
MouseGetPos, , , , itshwnd, 2
WinGetTitle, title, ahk_id %id%
WinGetClass, class, ahk_id %id%
WinGetTitle, A_Title, A
WinGetClass, A_class, A
controlgetfocus, keyboardcursor, A

ToolTip, --------------- under mouse cursor ---------------`nx: %xpos% `,  y: %ypos% `nahk_id %id%`nahk_class %class%`nitstilte: %title%`nControl: %control%`nitshwnd: %itshwnd%`nitscolor: %itscolor% `n`n---------------- active window ----------------`nactivewindow_class: %A_class%`nactivewindow_title: %A_Title%`nkeyboardcursor: %keyboardcursor%`n`n---------------- button detect ----------------`nrbutton_press: %right_button%`nlbutton_press: %left_button%`nA_PriorHotKey: %A_PriorHotKey%  ;;;`n是换行符

		;clipboard = %control%
return



^+7::
^Numpad7::
	MouseGetPos, xpos, ypos 
	MouseGetPos, , , id, control
	MouseGetPos, , , , itshwnd, 2

	WinGetTitle, title, ahk_id %id%
	WinGetClass, class, ahk_id %id%
	WinGetTitle, A_Title, A
	WinGetClass, A_class, A
	WinGetText, WinText, A
	Wingetpos, winx, winy, winw, winh, A
	WinGet, winProcessName, ProcessName, A

	PixelGetColor, itscolor, %xpos%, %ypos%
	controlgetfocus, keyboardcursor, A

	;mouseinfo = --------------- under mouse cursor ---------------`nx: %xpos% `,  y: %ypos% `nahk_id %id%`nahk_class %class%`nitstilte: %title%`nControl: %control%`nitshwnd: %itshwnd% `nitscolor: %itscolor% `n`n---------------- active window ----------------`nactivewindow_class: %A_class%`nactivewindow_title: %A_Title%`nkeyboardcursor: %keyboardcursor%`nwinx: %winx%`nwiny: %winy%`nwinw: %winw%`nwinh: %winh%`n`n---------------- button detect ----------------`nrbutton_press: %right_button%`nlbutton_press: %left_button%`nA_PriorHotKey: %A_PriorHotKey%`n`n---------------- startup ----------------`nA_Startup: %A_Startup%`nA_Desktop: %A_Desktop%`nA_ScriptDir: %A_ScriptDir% 
	mouseinfo = 
	(
	`r`n---------------- under mouse cursor ---------------
	`r`nx:%A_Tab%%A_Tab%%A_Tab%%xpos%
	`r`ny:%A_Tab%%A_Tab%%A_Tab%%ypos%
	`r`nahk_id:%A_Tab%%A_Tab%%A_Tab%%id%
	`r`nahk_class:%A_Tab%%A_Tab%%class%
	`r`nwintilte:%A_Tab%%A_Tab%%title%
	`r`nWinProcessName:%A_Tab%%A_Tab%%winProcessName%
	`r`nControlname:%A_Tab%%A_Tab%%control%
	`r`nitshwnd:%A_Tab%%A_Tab%%itshwnd%
	`r`nitscolor:%A_Tab%%A_Tab%%itscolor%
	`r`n
	`r`n----------------activewindow----------------
	`r`nwindow_class:%A_Tab%%A_Tab%%A_class%
	`r`nwindow_title:%A_Tab%%A_Tab%%A_Title%
	`r`nkeyboardcursor:%A_Tab%%A_Tab%%keyboardcursor%
	`r`nwinx:%A_Tab%%A_Tab%%A_Tab%%winx%
	`r`nwiny:%A_Tab%%A_Tab%%A_Tab%%winy%
	`r`nwinw:%A_Tab%%A_Tab%%A_Tab%%winw%
	`r`nwinh:%A_Tab%%A_Tab%%A_Tab%%winh%
	`r`n
	`r`n----------------buttondetect----------------
	`r`nA_PriorHotKey:%A_Tab%%A_Tab%%A_PriorHotKey%
	`r`n
	`r`n----------------startup----------------
	`r`nA_Startup:%A_Tab%%A_Tab%%A_Startup%
	`r`nA_Desktop:%A_Tab%%A_Tab%%A_Desktop%
	`r`nA_ScriptDir:%A_Tab%%A_Tab%%A_ScriptDir%
	`r`n
	`r`n
	`r`n----------------Active WinText----------------
	`r`n%WinText%
	)



	;sleep, 300
	;controlsettext, Edit1, %aaa%, 无标题 - 记事本

	;ahk_txt = d:\~ahk-temptext.txt  ;;选择d盘的原因是c盘在win7以上需要权限，FileAppend无法直接创建文件
	;winclose, ~ahk-temptext
	;ifexist, d:\~ahk-temptext.txt
	;{
	;Filedelete, d:\~ahk-temptext.txt
	;}
	;			FileAppend,
	;			(
	;			 %mouseinfo%
	;			), %ahk_txt%
	;run, d:\~ahk-temptext.txt

	Run Notepad
	WinWaitActive, ahk_class Notepad
	ControlSetText, Edit1, %mouseinfo%, A

return




ctrl & numpad6::  ;获取补料完整信息


cb := Clipboard
;cbrr := []
cbrr := StrSplit(cb, "`r`n")
cblr := cbrr.length()
existrr := []	


	ie := WBGet() 
	ie := ComObjCreate("InternetExplorer.Application")
	ComObjConnect(ie, "IE_"), loading := true 
	ie.Navigate("http://www.shipmentlink.com/servlet/TDB1_CargoTracking.do")
	while, loading
	{
	   Sleep, 10
	}
	tooltip, DONE!


Loop, % cblr
{
	

	blno := trim(cbrr[A_index]) ;155600015266, 155600016050
	if (blno = "" or existrr[blno] = 1 or instr(blno, "A") > 0 or instr(blno, "165") = 1 or InStr(blno, "EMC") = 1)
	{
		goto, tonextloop
	}
	tooltip % blno

	;;ie := IEGet("") 
	;ie := WBGet() 
	;text := ie.document.documentElement.innerText
	;;tooltip %text%
	;ie.document.getElementsByname("NO")[0].value := blno

	;ie.document.getElementsBytagname("input")[17].click()
	;;下面方法的等待网页似乎失效了, 需要用新的
	; Loop { ;等待网页加载完成!
	; Sleep,200
	; tooltip % ie.readyState
	; ;if (ie.readyState="complete" or ie.readyState=4 or A_LastError!=0)
	; break
	; } 

	;~ ie := ComObjCreate("InternetExplorer.Application")
	;~ ComObjConnect(ie, "IE_"), loading := true 
	;~ ie.Navigate("http://www.shipmentlink.com/servlet/TDB1_CargoTracking.do")
	;~ while, loading
	;~ {
	   ;~ Sleep, 10
	;~ }
	;~ msgbox, DONE!

	;;下面方法的等待网页才成功了...
	;ie := ComObjCreate("InternetExplorer.Application")
	;ie.Visible := True
	ComObjConnect(ie, "IE_"), loading := true ; Connect IE object & set var "loading" as TRUE
	;ie.Navigate("www.AutoHotkey.com")
	;~ Loop
	;~ {
		;~ sleep, 100
		;~ tooltip, % ie.document.getElementsByname("NO")[0].value
		;~ie.document.getElementsByname("NO")[0].focus()
		;~ie.document.getElementsByname("NO")[0].value := trim(blno)
		;~ if (ie.document.getElementsByname("NO")[0].value = trim(blno))
		;~ {
			;~ break
		;~ }
	;~ }
	ie.document.getElementsBytagname("input")[16].value := trim(blno)
	ie.document.getElementsBytagname("input")[17].click()
	while, loading
	{
	   Sleep, 10
	}
	tooltip, DONE!





	i := -1
	ci := 0 
	;之所以要用到这个ci检测, 因为table外还有table, 第一次得到的table是一个大table, 第二次才是需要的小table...
	totaltable := ie.document.getElementsBytagname("table").length
	tooltip % totaltable
	ietable := ""
	Loop, % totaltable
	{
		i := i + 1
		
		
		tt := ie.document.getElementsBytagname("table")[i]
		;tooltip % tt
		
		
		if (instr(tt.innertext, "Size/Type") > 1)
		{
			ci := ci + 1
			if (ci = 2)
			{
				
				ietable := ie.document.getElementsBytagname("table")[i]
				break
			}
		}
	}
	if (isobject(ietable) = false)  ;;非常重要, 用这个结合前面的ietable:="", 判断是否存在对象..., 对付没有成功的搜索, 甚至没有加载的网页, 都有效吗?
	{
		gettext := gettext "`r`n" "fail" A_tab A_tab A_tab A_tab A_tab A_tab A_tab A_tab  A_tab trim(blno)
		goto, tonextloop
	}
	
	
	
	tooltip % ietable.innertext

	tooltip % ietable.getElementsBytagname("td").length ;这个太重要, 不然会程序失败
	i := 9
	Loop,
	{
		i := i + 1
		;msgbox % i " - " ietable.getElementsBytagname("td")[i].innertext
		
		if (i = ietable.getElementsBytagname("td").length)
		{
			
			break
		}
		
		if (mod((i - 10), 9) = 0)
		{
			gettext := gettext "`r`n" replace(ietable.getElementsBytagname("td")[i].innertext, " ", "") ;ctnr no.
		}
		
		if (mod((i - 11), 9) = 0)
		{
			gettext := gettext A_tab replace(ietable.getElementsBytagname("td")[i].innertext, " ", "") ;ctnr type
		}
		
		if (mod((i - 12), 9) = 0)
		{
			;gettext := gettext A_tab A_Tab replace(ietable.getElementsBytagname("td")[i].innertext, " ", "")
			gettext := gettext A_tab replace(ietable.getElementsBytagname("td")[i].innertext, " ", "")
		} ;seal
		
		if (mod((i - 13), 9) = 0)
		{
			gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
		}
		
		if (mod((i - 14), 9) = 0)
		{
			gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
		}
		
		if (mod((i - 15), 9) = 0)
		{
			gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
		}
		
		if (mod((i - 16), 9) = 0)
		{
			gettext := gettext A_tab replace(ietable.getElementsBytagname("td")[i].innertext, " ", "")
		}
		
		if (mod((i - 17), 9) = 0)
		{
			gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
		}
		
		if (mod((i - 18), 9) = 0)
		{
			gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext  A_tab blno
		}
		
	}


	existrr[blno] := 1
	tonextloop:
}

msgbox % gettext
;clipboard := gettext
;msgbox % a_desktop
fileappend, % gettext, % a_desktop "\" A_now ".txt"

gettext := ""
tooltip


ie := ;
reload
return





ctrl & numpad9::  ;获取源自出场柜号的vgm信息


cb := Clipboard
;cbrr := []
cbrr := StrSplit(cb, "`r`n")
cblr := cbrr.length()
existrr := []	


	ie := WBGet() 
	ie := ComObjCreate("InternetExplorer.Application")
	ComObjConnect(ie, "IE_"), loading := true 
	ie.Navigate("http://www.shipmentlink.com/servlet/TDB1_CargoTracking.do")
	while, loading
	{
	   Sleep, 10
	}
	tooltip, DONE!
	
	




Loop, % cblr
{
	

	ctnr := trim(cbrr[A_index]) ;EGSU3039131
	if (ctnr = "" or existrr[ctnr] = 1)
	{
		goto, tonextlooppad9
	}
	tooltip % ctnr
	
	;;ie := IEGet("") 
	;ie := WBGet() 
	;text := ie.document.documentElement.innerText
	;;tooltip %text%
	;ie.document.getElementsByname("NO")[0].value := blno

	;ie.document.getElementsBytagname("input")[17].click()
	;;下面方法的等待网页似乎失效了, 需要用新的
	; Loop { ;等待网页加载完成!
	; Sleep,200
	; tooltip % ie.readyState
	; ;if (ie.readyState="complete" or ie.readyState=4 or A_LastError!=0)
	; break
	; } 

	;~ ie := ComObjCreate("InternetExplorer.Application")
	;~ ComObjConnect(ie, "IE_"), loading := true 
	;~ ie.Navigate("http://www.shipmentlink.com/servlet/TDB1_CargoTracking.do")
	;~ while, loading
	;~ {
	   ;~ Sleep, 10
	;~ }
	;~ msgbox, DONE!

	;;下面方法的等待网页才成功了...
	;ie := ComObjCreate("InternetExplorer.Application")
	;ie.Visible := True
	ComObjConnect(ie, "IE_"), loading := true ; Connect IE object & set var "loading" as TRUE
	;ie.Navigate("www.AutoHotkey.com")
	;~ Loop
	;~ {
		;~ sleep, 100
		;~ tooltip, % ie.document.getElementsByname("NO")[0].value
		;~ie.document.getElementsByname("NO")[0].focus()
		;~ie.document.getElementsByname("NO")[0].value := trim(blno)
		;~ if (ie.document.getElementsByname("NO")[0].value = trim(blno))
		;~ {
			;~ break
		;~ }
	;~ }
	
	totalinput := ie.document.getElementsBytagname("input").length
	tooltip % totalinput
	Loop, % totalinput - 1
	{
		
		vv := ie.document.getElementsBytagname("input")[A_Index].value
		;tvv := tvv "`r`n" a_index " - " vv
		;msgbox % tvv
		if (vv = "s_cntr" or vv = "m_cntr")
		{
			checkedindex := A_index
			;ie.document.getElementsBytagname("input")[A_Index].checked := true
			;break
		}
		
		if (vv = "Submit")
		{
			ctnrinputindex := A_index - 1 
			buttonindex := A_index
			
			;ie.document.getElementsBytagname("input")[A_index-1].value := trim(blno)
			;ie.document.getElementsBytagname("input")[A_index].click()
			;break
		}
		
	}
	;msgbox %tvv%
	;tvv := ""
	ie.document.getElementsBytagname("input")[checkedindex].checked := true
	ie.document.getElementsBytagname("input")[ctnrinputindex].value := trim(ctnr)
	ie.document.getElementsBytagname("input")[buttonindex].click()
	
	;ie.document.getElementsBytagname("input")[16].value := trim(blno)
	;ie.document.getElementsBytagname("input")[17].click()
	while, loading
	{
	   Sleep, 10
	}
	tooltip, DONE!
	


	;~ totaltd := ie.document.getElementsBytagname("td").length
	;~ ;tooltip % totalinput
	;~ Loop, % totaltd - 1
	;~ {
		
		;~ vv := ie.document.getElementsBytagname("td")[A_Index].innertext
		;~ ;tvv := tvv "`r`n" a_index " - " vv
		;~ ;msgbox % tvv
		;~ if (vv = "s_bk")
		;~ {
			;~ ie.document.getElementsBytagname("td")[A_Index].checked := true
			;~ break
		;~ }
		
	;~ }







	i := -1
	ci := 0 
	;之所以要用到这个ci检测, 因为table外还有table, 第一次得到的table是一个大table, 第二次才是需要的小table...
	totaltable := ie.document.getElementsBytagname("tr").length
	;msgbox % totaltable
	ietable := ""
	Loop, % totaltable - 1
	{
		i := i + 1
		
		
		tt := ie.document.getElementsBytagname("tr")[i]
		;msgbox % tt.innertext
		
		
		if (instr(tt.innertext, "Size/Type") > 1) ;Full return to ;Size/Type
		{
			;msgbox % tt.innertext " - " instr(tt.innertext, "Size/Type")
			ci := i + 1
			ietable := ie.document.getElementsBytagname("tr")[ci]
			;msgbox % ietable.innertext
			;break ;不要break了, 因为可能外框里有,内框里有, 还有第n层内里也有
			;而我们要的是最后一层
		}
	}
	if (isobject(ietable) = false)  ;;非常重要, 用这个结合前面的ietable:="", 判断是否存在对象..., 对付没有成功的搜索, 甚至没有加载的网页, 都有效吗?
	{
		gettext := gettext "`r`n" trim(ctnr) A_tab A_tab A_tab A_tab A_tab A_tab A_tab A_tab  A_tab A_tab A_tab A_tab  ;trim(blno)
		goto, tonextlooppad9
	}
	
	
	
	;msgbox % ietable.innertext

	tooltip % ietable.getElementsBytagname("td").length ;这个太重要, 不然会程序失败
	tttd := ietable.getElementsBytagname("td").length
	
		A_ctnr := trim(ietable.getElementsBytagname("td")[0].innertext)
		A_size := trim(ietable.getElementsBytagname("td")[1].innertext)
		A_date := trim(ietable.getElementsBytagname("td")[2].innertext)
		A_move := trim(ietable.getElementsBytagname("td")[3].innertext)
		A_location := trim(ietable.getElementsBytagname("td")[4].innertext)
		A_velvoy := trim(ietable.getElementsBytagname("td")[5].innertext)
		A_method := trim(ietable.getElementsBytagname("td")[6].innertext)
		A_vgm := trim(ietable.getElementsBytagname("td")[7].innertext)
		
		gettext := gettext A_ctnr A_tab A_size A_tab A_date A_tab A_move A_tab A_location A_tab A_velvoy A_tab A_method A_tab A_vgm "`r`n"
	
	;~ Loop, % tttd - 1 ;为了对付一个提单查到两个分表格的情况
	;~ {
		
		
		;~ ;msgbox % A_index "- " ietable.getElementsBytagname("td")[a_index].innertext
		;~ if (ietable.getElementsBytagname("td")[a_index].innertext = "Full return to") ;为了对付一个提单查到两个分表格的情况
		;~ {
			;~ firsti := A_index + 1
			
			;~ ;msgbox % firsti
			;~ i := firsti - 1
			;~ Loop,
			;~ {
			;~ i := i + 1
			;~ ;msgbox % i " - " ietable.getElementsBytagname("td")[i].innertext
			
			;~ if (i = ietable.getElementsBytagname("td").length)
			;~ {
				
				;~ break
			;~ }
			
			;~ if (instr(ietable.getElementsBytagname("td")[i].innertext, "Container Activity" ) > 0) ;为了对付一个提单查到两个分表格的情况
			;~ {
				;~ gettext := gettext "`r`n"
				;~ break
			;~ }
			
			;~ if (mod((i - firsti - 0), 12) = 0)
			;~ {
				;~ gettext := gettext "`r`n" replace(ietable.getElementsBytagname("td")[i].innertext, " ", "")
			;~ }
			
			;~ if (mod((i - firsti - 1), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 2), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 3), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 4), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 5), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 6), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 7), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 8), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 9), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 10), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext
			;~ }
			
			;~ if (mod((i - firsti - 11), 12) = 0)
			;~ {
				;~ gettext := gettext A_tab ietable.getElementsBytagname("td")[i].innertext A_tab blno
			;~ }
			
			;~ }
			
		;~ }
		

		
		
	;~ }
	
;;
	

	existrr[blno] := 1
	tonextlooppad9:
}

msgbox % gettext
;clipboard := gettext
;msgbox % a_desktop
fileappend, % gettext, % a_desktop "\" A_now ".txt"

gettext := ""
tooltip

ie := ;

return



ctrl & NumpadMult::  ;获取报关放心信息





;~ SetCapsLockState, off
;~ ;SwitchIME2("00000804")
;~ SwitchIME2("00000409")


excel := ComObjActive("Excel.Application")
xl := excel.sheets["明细"]

;MsgBox % excel.activecell.Row ;成功!
;MsgBox % excel.selection.Count ;成功
;MsgBox % excel.selection.Rows(1).Row ;成功
;MsgBox % excel.selection.Rows(excel.selection.Rows.Count).Row ;成功

	

	
	xllr := xl.Cells(65536, "c").End(-4162).Row  ;-4121是xldown
	drr0 := []
	drr0 := xl.range["c" 1 ":n" xllr].value 
	
	frow := excel.selection.Rows(1).Row ;成功
	loop
	{
		if (frow = 8 or drr0[frow,1] = "新一票")
		{
			;MsgBox % "done - " frow "  " drr0[frow,1]
			break
		}else
		{
			frow--
			;MsgBox % frow
		}
		
	}
	
	lrow := excel.selection.Rows(excel.selection.Rows.Count).Row ;成功
	loop
	{
		if (lrow = xllr or drr0[lrow,1] = "结束")
		{
			;MsgBox % "done - " lrow "  " drr0[lrow,1]
			break
		}else
		{
			lrow++
			;MsgBox % lrow
		}
		
	}
	
	
	
	drr := []
	drr := xl.Range["c" frow ":n" lrow].value
	xl.Range["c" frow ":n" lrow].select
	;MsgBox % drr[1,1]
	;MsgBox % drr[2,2]
	
	;nfile =
	;(
	;`r`ndrr[1,1] - drr[1,2]
	;`r`ndrr[2,1] - drr[2,2]
	;)
	
	;fileappend, %nfile%, %A_Desktop%\Export_%velname%_%voy%_%a_now%.xsd
	
	;MsgBox Ok
	
	
	

	ie := WBGet() 
	ie := ComObjCreate("InternetExplorer.Application")
	ComObjConnect(ie, "IE_"), loading := true 
	ie.Navigate("http://ict.zjport.com/main.aspx?NAVID=EDRelaseQuery&q=0")
	while, loading
	{
	   Sleep, 10
	}
	tooltip, DONE!




	filename := "clearance_" A_Now ".txt"
	i := 1
	loop
	{
		
		if (i > lrow - frow + 1)
		{
			break
		}
		
		if (drr[i,1] = "结束")
		{
			bl := drr[i, 2]
			
			;ie := WBGet() 
			;ie := ComObjCreate("InternetExplorer.Application")
			;ComObjConnect(ie, "IE_"), loading := true 
			;ie.Navigate("http://ict.zjport.com/main.aspx?NAVID=EDRelaseQuery&q=0")
			;while, loading
			;{
			;   Sleep, 10
			;}
			;tooltip, DONE!
			
			
			ie.document.getElementById("_ctl0_ContentPlaceHolder1_QueryInput1_TEXT_2999").value := bl
			ie.document.getElementById("_ctl0_ContentPlaceHolder1_QueryInput1_btnOK").Click()
			;_ctl0_ContentPlaceHolder1_QueryInput1_btnOK
			
			
			
			while, loading
			{
			   Sleep, 10
			}
			tooltip, DONE!	
			Sleep, 2000
			
			
			loop
			{
				ie1 := WBGet("查询结果") 
				;~ while, loading
				;~ {
				   ;~ Sleep, 10
				;~ }
				;~ tooltip, DONE!	
				waittext := ie1.locationURL
				if (waittext <> "")
				{
					break
				}
			}
			
			;MsgBox % ie1.document.getElementsByTagName("table")[2].innertext ;innerhtml
			targettb := ie1.document.getElementsByTagName("table")[2]
			targettr := targettb.getElementsByTagName("tr")[1]
			if (isobject(targettr) = true) ;;非常重要, 用这个结合前面的ietable:="", 判断是否存在对象..., 对付没有成功的搜索, 甚至没有加载的网页, 都有效吗?
			{
				targettext := targettr.innertext
				if (InStr(targettext, bl) > 0)
				{
					
					ToolTip % targettext
					fileappend, %bl%`r`n, %A_Desktop%/%filename%
				}
			}
			
			
			ie1 := ;
			WinClose, 查询结果
			
			
		}
		
		i++
	}


	
	
	ie := ;
	
	MsgBox Ok!
	ToolTip
	
	reload
return





ctrl & Numpad3::  ;;生成进口报文, 单一窗口


gosub, minuscert
if (FileExist("C:\systemtemplog.ini") = false )
{
	tooltip, Unauthorized entering may lead to critical system data corruption... a considerable step is to shutdown your computer...
	
	sleep, 2000
	reload
}

SetCapsLockState, off
;SwitchIME2("00000804")
SwitchIME2("00000409")


excel := ComObjActive("Excel.Application")

isExistM3 := 0
	for ex in excel.worksheets
	{
		;MsgBox % ex.Name
		
		if ( ex.Name = "M3" )
		{
			xl := ex
			isExistM3 := 1
			break
		}
		
	}
	
if (isExistM3 <> 1)
{
xl := excel.sheets["明细"]
}
;MsgBox % IsObject(xl)


;MsgBox % excel.activecell.Row ;成功!
;MsgBox % excel.selection.Count ;成功
;MsgBox % excel.selection.Rows(1).Row ;成功
;MsgBox % excel.selection.Rows(excel.selection.Rows.Count).Row ;成功

	
	
	
headrr := []
headrr := xl.range["c" 1 ":n" 7].value 
	

zjetd := headrr[3,10]
hketa := headrr[3,11]
vneta := headrr[5,11]

agentpre := agentpre
agencycode := agencycode
agentname := agentname
loadingportcode := loadingportcode
loadingportcustomscode := loadingportcustomscode

prename := headrr[3,1]
voy := headrr[3,4]

velname := substr(prename,instr(prename,"(",false,1) + 1 ,instr(prename,")",false,1) - instr(prename,"(",false,1) - 1)



	
	xllr := xl.Cells(65536, "c").End(-4162).Row  ;-4121是xldown
	drr0 := []
	drr0 := xl.range["c" 1 ":n" xllr].value 
	
	frow := excel.selection.Rows(1).Row ;成功
	loop
	{
		if (frow = 8 or drr0[frow,1] = "新一票")
		{
			;MsgBox % "done - " frow "  " drr0[frow,1]
			break
		}else
		{
			frow--
			;MsgBox % frow
		}
		
	}
	
	lrow := excel.selection.Rows(excel.selection.Rows.Count).Row ;成功
	loop
	{
		if (lrow = xllr or drr0[lrow,1] = "结束")
		{
			;MsgBox % "done - " lrow "  " drr0[lrow,1]
			break
		}else
		{
			lrow++
			;MsgBox % lrow
		}
		
	}
	
	
	
	;drr := []
	;drr := xl.Range["c" frow ":n" lrow].value
	xl.Range["c" frow ":n" lrow].select
	;MsgBox % drr[1,1]
	;MsgBox % drr[2,2]
	

	


;xllr := xl.Cells(65536, "c").End(-4162).Row  ;-4121是xldown



;fileread, velinfotext, %A_ScriptDir%\vel_imo_carriercode.ini
velinfo := []
portdaterr := []
porttransrr := []
agentpre := ""
agencycode := ""
loadingportcode := ""
loadingportcustomscode := ""
Loop, read, %A_ScriptDir%\vel_imo_carriercode.ini
{
    ;~ Loop, parse, A_LoopReadLine, %A_Tab%
    ;~ {
        ;~ MsgBox, Field number %A_Index% is %A_LoopField%.
;~ }
if (agentpre = "")
{
agentpre := myextract("<agentpre>", "</agentpre>", A_LoopReadLine, 1)
}
if (agencycode = "")
{
agencycode := myextract("<agentcode>", "</agentcode>", A_LoopReadLine, 1)
}

if (agentname = "")
{
agentname := myextract("<agentname>", "</agentname>", A_LoopReadLine, 1)
}

if (loadingportcode = "")
{
loadingportcode := myextract("<loadingportcode>", "</loadingportcode>", A_LoopReadLine, 1)
}

if (loadingportcustomscode = "")
{
loadingportcustomscode := myextract("<loadingportcustomscode>", "</loadingportcustomscode>", A_LoopReadLine, 1)
}

if (defaultFirstCnPort = "")
{
defaultFirstCnPort := myextract("<defaultFirstCnPort>", "</defaultFirstCnPort>", A_LoopReadLine, 1)
}

if (defaultLastForeignPort = "")
{
defaultLastForeignPort := myextract("<defaultLastForeignPort>", "</defaultLastForeignPort>", A_LoopReadLine, 1)
}




pdstr := myextract("<portpassingdate>", "</portpassingdate>", A_LoopReadLine, 1)
if (pdstr <> "" )
{
	port := StrSplit(pdstr, ".")[1]
	portEdate := StrSplit(pdstr, ".")[2]
	portIdate := StrSplit(pdstr, ".")[3]
	portdaterr[port, "E"] := portEdate
	portdaterr[port, "I"] := portIdate
	;MsgBox % port "-" portdaterr[port, "E"] "-" portdaterr[port, "I"]
}

ptstr := myextract("<porttrans>", "</porttrans>", A_LoopReadLine, 1)
if (ptstr <> "" )
{
	portstr := StrSplit(ptstr, ".")[1]
	portcode := StrSplit(ptstr, ".")[2]
	porttransrr[portstr] := portcode
	;MsgBox % portstr "-" portcode "-" porttransrr[portstr]
}


nvelname := myextract("(", ")", A_LoopReadLine, 1)
nimo := myextract("[", "]", A_LoopReadLine, 1)
ncarriercode := myextract("{", "}", A_LoopReadLine, 1)
nvelcnname := myextract("<", "(", A_LoopReadLine, 1)
ncarriername := myextract("}", "@", A_LoopReadLine, 1)
;ncarrieraddr := myextract("@", "/", A_LoopReadLine, 1)
ncarriertel := myextract("@", "/", A_LoopReadLine, 1)
nfirstforgeignport := myextract("/", "#", A_LoopReadLine, 1)
;nfirstdateusing := myextract("#", "|", A_LoopReadLine, 1)
;~ myextract(cut1, cut2, oldtext, cutcount)
         ;~ ;cut1 截取字段前面的字符
		 ;~ ;cut2 截取字段后面的字符
		 ;~ ;oldtext 需截取的整段字符
		 ;~ ;cutcount 第几次截取
velinfo[nvelname, 1] := nvelname
velinfo[nvelname, 2] := nvelcnname
velinfo[nvelname, 3] := nimo
velinfo[nvelname, 4] := ncarriercode
velinfo[nvelname, 5] := ncarriername
;velinfo[nvelname, 6] := ncarrieraddr
velinfo[nvelname, 7] := ncarriertel	
velinfo[nvelname, 8] := nfirstforgeignport	
;velinfo[nvelname, 9] := nfirstdateusing
}


;MsgBox % portdaterr["VNHPH", "E"] "-" portdaterr["VNHPH", "I"]

	headrr := []
	headrr := xl.range["c" 1 ":n" 7].value 
	;doingrr := []
	;doingrr := xl.range["c" 8 ":ag" xllr].value 
	
	;msgbox % startrow " - " endrow
	;msgbox % doingrr[startrow, 1]


zjetd := headrr[3,10]
hketa := headrr[3,11]
vneta := headrr[5,11]

agentpre := agentpre
agencycode := agencycode
loadingportcode := loadingportcode
loadingportcustomscode := loadingportcustomscode

prename := headrr[3,1]
voy := headrr[3,4]

velname := substr(prename,instr(prename,"(",false,1) + 1 ,instr(prename,")",false,1) - instr(prename,"(",false,1) - 1)

loop
{
	velimo := velinfo[velname, 3]
	if (Trim(velimo) <> "" )
	{
		break
	}else
	{
		InputBox, xvelimo, 请输入imo号码
		velimo := xvelimo
	}
}
;velimo := velinfo[velname, 3]
velcnname := velinfo[velname, 2]
carriercode := velinfo[velname,4]
carriername := velinfo[velname,5]
carrieraddr := carriername
carriertel := velinfo[velname,7]
firstforgeignport := velinfo[velname,8] ;"HKHKG"
;firstdateusing := velinfo[velname,9] ;从离港到第一个境外港, 需要多长时间
firstdateusing := portdaterr[firstforgeignport, "E"] ;从离港到第一个境外港, 需要多长时间, 这个地方进出口不一样的


sarr := []
cnrr := []
xllr := xl.Cells(65536, "c").End(-4162).Row  ;-4121是xldown

	


	;sarr := xl.Range["c" frow ":n" lrow].value
	sarr := xl.Range["c" 1 ":n" xllr].value
	;cnrr := xl.Range["AG" 1 ":AG" lrow].value ;ag列是拼箱的判断
		i := frow
		loop
		{
			;ToolTip, % i
			if(i > xllr)
			{
				break
			}else if (sarr[i,1] = "输入柜号")
			{
				ctnr := replace(replace_hhtab(sarr[i,3])," ","") ntot(replace(replace_hhtab(sarr[i,4])," ", ""))
				
				;用数字计算出现的次数
				temp := 0
				temp := cnrr[ctnr] + 0
				temp++
				cnrr[ctnr] := temp
				;ToolTip % ctnr "   " cnrr[ctnr]
				
				;用字符串计算出现的次数
				cnrr[ctnr, "bl"] .= "/" 
				
			}
			
			i++
		}
	
	;MsgBox % cnrr["HMCU9103329"]
	;MsgBox % cnrr["EGSU9039139"]
	;MsgBox % cnrr["EGHU3090206"]
	;cnrr := []
	;cnrr["EGHU3090206", "bl"] .= "/"
	;cnrr["EGHU3090206", "bl"] .= "/"
	;cnrr["EGHU3090206", "bl"] .= "/"
	;MsgBox % StrLen(cnrr["EGHU3090206", "bl"])
	
	
	stime := A_Now
	FormatTime, stime, % stime, yyyyMMddHHmmss
	stime0 := stime A_TickCount
	stime .= "000"
	
	nfile := ""
	nfile = <?xml version="1.0" encoding="UTF-8"?>`r`n

	nfile .= "<Manifest>`r`n" 
	nfile .= "	<Head>`r`n" 
	nfile .= "		<MessageID>" agentpre stime0 "</MessageID>`r`n" ;报文编号
	nfile .= "		<FunctionCode>9</FunctionCode>`r`n" ;报文功能代码 进出都fixed="9"
	nfile .= "		<MessageType>MT1101</MessageType>`r`n"
	nfile .= "		<SenderID>" agencycode "</SenderID>`r`n" ;发送方代码
	nfile .= "		<ReceiverID>" loadingportcustomscode "</ReceiverID>`r`n" ;接收方代码, 是否6711? 湛江海关代码
	
	;FormatTime, inputnow, %A_now% yyMMddHHmmss

	nfile .= "		<SendTime>" stime "</SendTime>`r`n" ;发送时间, 格式是什么? 
	nfile .= "		<Version>" "1.0" "</Version>`r`n" ;报文版本号, 是什么? 1.0
	nfile .= "	</Head>"
	
				dstr := headrr[3,2]
				;dstr := "17-01-1" ; 这里有个问题, 有些电脑的日期显示, 是2017.1.18, 这个要在设置, 日期显示, 那里改为2017-1-18
				dstr := StrReplace(dstr, "." , "-") ;这个是210112新增的, 为了解决上面那一行的日期格式是.的问题


				dstrrr := StrSplit(dstr, "-")
				dyear := strreplace(format("{:4}", dstrrr[1]), "  ", "20")
				dmonth := strreplace(format("{:2}", dstrrr[2]), " ", "0")
				ddate := strreplace(format("{:2}", dstrrr[3]), " ", "0")
				ETAZJdate := dyear dmonth ddate "230000" ;这个就是到达湛江港的时间了, 已经转换好, 随时可以加减

				;msgbox % ((dyear + 0) < (A_Year + 0))
				If ( ((dyear + 0) < (A_Year + 0)) And ( (dmonth + 0) <= (A_Mon + 0) ) ){
					Loop{
						InputBox, WrongYear, 年份错误, 严重错误-判断年份有误
					}
				}
				
				FormatTime, adate, % ETAZJdate, yyyyMMddHHmmss
				;MsgBox % adate
				adate += portdaterr[defaultFirstCnPort, "I"], Days
				;MsgBox %  portdaterr[defaultFirstCnPort, "I"]
				adate += -1, Days
				;adate .= "230000"
				FormatTime, adate, % adate, yyyyMMddHHmmss
				
				sailingdate := ETAZJdate
				sailingdate += portdaterr[defaultLastForeignPort, "I"], Days
				;sailingdate += -1
				FormatTime, sailingdate, % sailingdate, yyyyMMddHHmmss
				
				defaultLastForeignPortETD := sailingdate
				defaultFirstCnPortETA := adate
				InputBox, setFirstCnPortSTR, 境外最后港/境外港离港时间 -> 境内第一港/境内港抵达时间,,,,,,,,, %defaultLastForeignPort%/%defaultLastForeignPortETD% -> %defaultFirstCnPort%/%defaultFirstCnPortETA%
						;sFCPStr1 := []
						sFCPStr := StrSplit(setFirstCnPortSTR, " -> ")[1]
						setLastPort := StrSplit(sFCPStr, "/")[1]
						setLastPortDate := StrSplit(sFCPStr, "/")[2]
						
						;sFCPStr2 := []
						sFCPStr := StrSplit(setFirstCnPortSTR, " -> ")[2]
						setFirstPort := StrSplit(sFCPStr, "/")[1]
						setFirstPorttDate := StrSplit(sFCPStr, "/")[2]
					
	nfile .= "`r`n" "	<Declaration>"
	nfile .= "`r`n" "		<RepresentativePerson>"
	nfile .= "`r`n" "			<Name>" agencycode "</Name>"  ;舱单传输人数据段, 但是这里却不是外代, 而是海关备案代码或者18位统一信用证
	nfile .= "`r`n" "		</RepresentativePerson>"
	nfile .= "`r`n" "		<ExitCustomsOffice>"
	nfile .= "`r`n" "			<ID>" setLastPort "</ID>" ;运输工具离境地海关代码
	nfile .= "`r`n" "		</ExitCustomsOffice>"
	nfile .= "`r`n" "		<Agent>"
	nfile .= "`r`n" "			<ID>" agencycode "</ID>" ;运输工具代理企业代码
	nfile .= "`r`n" "		</Agent>"
	nfile .= "`r`n" "		<Carrier>"
	nfile .= "`r`n" "			<ID>" carriercode "</ID>" ;承运人数据段, 但是这里居然不是代码carriercode, 而是用了船名, 看船务的记录, 进出都是
														;180525, 胡鹏在56号令宣讲中, 改回真正的carriercode, 可以是数字, 也可以是简写, 比如长荣EMC, 万海WHL, 可在vel..ini里改 
	nfile .= "`r`n" "		</Carrier>"
	nfile .= "`r`n" "		<BorderTransportMeans>"
	nfile .= "`r`n" "			<JourneyID>" voy "</JourneyID>" ;航次航班编号
	nfile .= "`r`n" "			<TypeCode>" 1 "</TypeCode>" ;运输方式代码
	nfile .= "`r`n" "			<ID>" velimo "</ID>" ;运输工具代码
	nfile .= "`r`n" "			<Name>" velname "</Name>" ;运输工具名称
	
	nfile .= "`r`n" "			<FirstArrivalLocationID>" setFirstPort "</FirstArrivalLocationID>" ;进口: 运输工具抵达关境内第一个目的港代码（循环次数：0-1
	nfile .= "`r`n" "			<ArrivalDateTime>" setFirstPorttDate "</ArrivalDateTime>" ;运输工具抵达关境内第一个目的港的日期和时间
	
				;departuredate .= headrr[3,10] "230000"
				;FormatTime, departuredate, % departuredate, yyyyMMddHHmmss
				
	nfile .= "`r`n" "			<DepartureDateTime>" setLastPortDate "</DepartureDateTime>" ;运输工具启运日期和时间
	nfile .= "`r`n" "		</BorderTransportMeans>"
	
	
	
	
	
	
	;;;循环做一票一票的提单了
	i := frow
	loop
	{
		
		if(i > lrow)
		{
			break
		}
		
		
		
		
		if (sarr[i,1] = "新一票")  ;当遇到"新一票"时, 生成这些东西, 这是三大块里的第一大块, 而第二大块是集装箱号, 会对应"输入柜号"来生成, 第三大块是货物信息, 对应"结束生成"
		{
			
			
			;;;查报关提单号, 总柜数, 
			ii := i
			ttctnrnum := 0
			loop
			{
				
				
				if (sarr[ii,1] = "结束")
				{
					blno := ntot(replace(replace_hhtab(sarr[ii, 2]), " ", "")) ;提单号
					break
				}else
				{
					ttctnrnum++
				}
				ii++
			}
			
			
			shipper := replace_hhtab(sarr[i, 2]) ;发货人 ;其实进口时是收货人, 但后面的shipperName什么的, 是正确对应发货人的, consinee是正确对应收货人的
			
				if (instr(shipper, "[,]") > 0) ;新模板 
				{
					isnew = 1
					shipper_rr := Strsplit(strsplit(shipper,"[|]")[2],"[,]") ;外国货主
						shipperCountry := shipper_rr[1] ;
							if (shipperCountry = "CN" || shipperCountry = "")
							{
								InputBox, baddata, % blno, % blno "发货人国家有问题吧: " shipperCountry "`r`n`r`n导出失败, ..."
								Reload
							}
						shipperName := shipper_rr[2]
							shipperName := replaceall(shipperName, " ", "'", "$", "&", "*", "#", "^", "!", "@", "`r`n", Chr(10), Chr(9))
						shipperID := shipper_rr[3]
							shipperID :=  countryCompanyTypeMatch(shipperCountry) "+"  RegExReplace(shipperID, "^[a-zA-Z ]{2,}\+", "") ; "USCI+" shipperID
						shipperAddr := shipper_rr[4]
							shipperAddr := replaceall(SubStr(shipperAddr, 1, 70), " ", "'", "$", "&", "*", "#", "^", "!", "@", "`r`n", Chr(10), Chr(9))
							;MsgBox % shipperAddr
						shipperTel := shipper_rr[5]
						shipperPerson := shipper_rr[6]
						shipperPerson := replaceall(shipperPerson, " ", "'", "$", "&", "*", "#", "^", "!", "@", "`r`n", Chr(10), Chr(9))
						
					consignee_rr := StrSplit(strsplit(shipper,"[|]")[1],"[,]") ;中国货主
						consigneeCountry := consignee_rr[1]
						consigneeName := consignee_rr[2]
							consigneeName := replaceall(consigneeName, " ", "'", "$", "&", "*", "#", "^", "!", "@", "`r`n", Chr(10), Chr(9))
						consigneeID := consignee_rr[3]
							consigneeID := countryCompanyTypeMatch(consigneeCountry) "+" RegExReplace(consigneeID, "^[a-zA-Z ]{2,}\+", "") ;"9999" consigneeID
						consigneeAddr := consignee_rr[4]
							consigneeAddr := replaceall(SubStr(consigneeAddr, 1, 70), " ", "'", "$", "&", "*", "#", "^", "!", "@", "`r`n", Chr(10), Chr(9))
							;MsgBox % consigneeAddr
						consigneeTel := consignee_rr[5]
						consigneePerson := consignee_rr[6]
						consigneePerson := replaceall(consigneePerson, " ", "'", "$", "&", "*", "#", "^", "!", "@", "`r`n", Chr(10), Chr(9))
				}else ;旧模板
				{
					
					isnew = 0
					shipperCountry := ""
					shipperName := carriername
					shipperID := carriercode
						shipperID := shipperID := countryCompanyTypeMatch(shipperCountry) "+" shipperID ;"9999" shipperID
					shipperAddr := carrieraddr
					shipperTel := carriertel
					shipperPerson := carriername
					
					consigneeCountry := "CN"
					consigneeName := shipper
					consigneeID := "X0000000000000000X"
						consigneeID := countryCompanyTypeMatch(consigneeCountry) "+" consigneeID ;"USCI+" consigneeID
					consigneeAddr := consigneeName
					consigneeTel := "07592381019"
					consigneePerson := consigneeName
						
						
				}
			
			
			cargo := Trim(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace_hhtab(sarr[i, 4]), "宝满提吉, 还重宝满",""),"拖装", ""),"场内装", ""),"吉出重回", ""),"海铁联运", ""),"港内装", ""),"宝满", ""),"PNCO1EVG",""),"PNCO1EL",""),"PNCO1OCL",""),"PNCO1OL",""),"26T",""),"沿海转运", ""),"外代长荣", ""),"指定柜",""),"任取柜","")) ;货名
			cargo := replace(replace(cargo, "KGS)[|]", "[|]"), "[,](","[,]")
			cargo := replaceall(cargo, " ", "'", "$", "&", "*", "#", "^", "!", "@", "`r`n", Chr(10), Chr(9))
			
			
			;if (InStr(cargo, "吉柜") + InStr(cargo, "吉箱") + InStr(cargo, "空柜") + InStr(cargo, "空箱" ) > 0) 
			if (InStr(cargo, "吉柜") > 0) 
			{
				emorfull := "4"
				CustomsStatusCode := "004"
			}else
			{
				emorfull := "5"
				CustomsStatusCode := "001"
			} ;else, 其实还有个拼箱问题, 需要结合封条处 和 AG列来判断
			
			
			pkgnum := ntot(replace(replace_hhtab(sarr[i, 6]), " ", "")) ;包装件数
				if (pkgnum = "" or pkgnum = 0)
				{
					InputBox, wnum , 件数不能为0, %blno% 件数不能为0, , , , , , , , %blno%%A_Tab%件数不能为0
					xl.Range("c" i ":j" i).activate
					MsgBox 退出!
					Reload
				}
				
				
			pkgtypepre := replace(replace_hhtab(sarr[i, 7]), " ", "") ;包装类型
			pkgtype := pkgTypeMatch(pkgtypepre)
			
			gw := ntot(replace(replace_hhtab(sarr[i, 8]), " ", "")) ;毛重
				if (gw = "" or gw = 0)
				{
					InputBox, wnum , 毛重不能为0, %blno% 毛重不能为0, , , , , , , , %blno%%A_Tab%毛重不能为0
					xl.Range("c" i ":j" i).activate
					MsgBox 退出!
					Reload
				}
			
			mt := Round(gw/1000, 0) ;体积
				if (mt = 0)
				{
					mt := 1
				}
			
			dangerStr := replace_hhtab(sarr[i, 5]) ;危险品
			; dangerStr := replaceall(dangerStr, "", "UN")
			; dangerStr := replaceall(dangerStr, "", "NO")
			; dangerStr := replaceall(dangerStr, "", ".")
			; dangerStr := replaceall(dangerStr, "", ":")
			; dangerStr := replaceall(dangerStr, "", "un")
			; dangerStr := replaceall(dangerStr, "", "no")
			; dangerStr := replaceall(dangerStr, "", "。")
			; dangerStr := replaceall(dangerStr, "", "：")
			dangerCode := StrSplit(dangerStr, "[,]")[2]

			; 函数：提取字符串中的所有数字并连续拼接
			ExtractNumbers(inputStr) {
				foundNumbers := ""
				RegExMatch(inputStr, "O)(\d+)", match)  ; 找到第一个匹配项
				
				; 循环查找所有数字
				while (match.Count()) {
					foundNumbers .= match[1]  ; 添加找到的数字
					inputStr := SubStr(inputStr, match.Pos(1) + match.Len(1))  ; 移除已处理的部分
					
					; 查找下一个数字
					RegExMatch(inputStr, "O)(\d+)", match)
				}
				
				return foundNumbers
			}
			dangerCode := ExtractNumbers(dangerCode)  ; 2507171521 处理危险品

				if (isnew = 1)
				{
					cargorr := StrSplit(cargo, "[|]")
					cargoTotalNum := cargorr.MaxIndex() - 1
					Loop % cargoTotalNum
					{
						eachCargoNum%A_Index% := A_Index
						eachCargoRR%A_Index% := StrSplit(cargorr[A_Index], "[,]")
						eachCargoName%A_Index% := eachCargoRR%A_Index%[1]
						eachCargoPkgNum%A_Index% := eachCargoRR%A_Index%[2]
						eachCargoPkgName%A_Index% := eachCargoRR%A_Index%[3]
						eachCargoGW%A_Index% := eachCargoRR%A_Index%[4]
					}
				}else ;旧模板
				{
						cargoTotalNum := 1
						
						eachCargoNum1 := 1
						eachCargoRR1 := StrSplit(cargo "[,]"  pkgnum "[,]" pkgtypepre "[,]" gw, "[,]")
						eachCargoName1 := eachCargoRR1[1]
						eachCargoPkgNum1 := eachCargoRR1[2]
						eachCargoPkgName1 := eachCargoRR1[3]
						eachCargoGW1 := eachCargoRR1[4]
				}
			
			
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			if (InStr(sarr[i, 3], "[,]") > 0)
			{
				portfullstr :=  Trim(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace_hhtab(sarr[i, 3]),"拖装", ""),"场内装", ""),"吉出重回", ""),"海铁联运", ""),"港内装", ""),"宝满", ""),"PNCO1EVG",""),"PNCO1EL",""),"26T", ""), " ", "")) ;港口
				portfullstr := replace(replace(replace(replace(portfullstr," WEST PORT", "")," NORTH PORT",""), " EAST PORT", ""), " SOUTH PORT", "")
				
				portrr := StrSplit(portfullstr, "[,]")
				portfull := portrr[1]
				portCountryCode := portrr[3] ;;/
				;MsgBox % portCountryCode
				portfull := portfull
				portCountryCode := portCountryCode
				portcode := portMatch(portCountryCode, portfull)
				portdate := portTimeMatch(portCountryCode, 2) ;参数1出口, 其余进口
					if (portcode = "")
					{
						
						
						InputBox, wronginfo, "没有发货港信息!", "无发货港信息 请检查后重新录入!" ,,,,,,,, % portfull
						reload
						
					}
					
					if (portCountryCode = "CN" || portCountryCode = "")
					{
						InputBox, baddata, % blno, % blno "港口国家有问题吧: " portCountryCode "`r`n`r`n导出失败, ..."
						Reload
					}
				
				;;中转港的问题, 现在还没有考虑, 但是估计要分析
				;;注意, transPortMatch得到的是一个数组, [2]是HKHKG [3]是出口到达天数 1 [4]是进口香港离港距离天数, -20


				
				if (Trim(portrr[4]) = "") ;无中转港信息, 有可能发货港就是中转港, 则船东会留空
				{
					;transportCode := portcode
					;transportDate := transPortMatch(portfull)[4]
					
					;;下面这段本来没有, 但是180525胡鹏要求用中转港信息填入发货港, 时间也是, 所以
					portdate := transPortMatch(portfull)[4]
					if (portdate = 0 || portdate = "")
					{
						InputBox, wronginfo, "没有此中转港对应的日期!", "没有此中转港对应的日期  请检查后重新录入!" ,,,,,,,, % portfull
						Reload
					}

					;;191115新增, 本次新增数据项, 货物托运地点, 我的理解, 这次不能通过中装港绕开了, 那么以后检查就要多留心才行
					actualPortCode := portcode
					actualPortDate := portdate

					
				}else ;有中转港
				{
					transportCode := transPortMatch(portrr[4])[2]
					transportDate := transPortMatch(portrr[4])[4]
					if (transportDate = 0 || transportDate = "" || transportCode = "")
					{
						InputBox, wronginfo, "没有此中转港信息!", "没有此中转港信息  请检查后重新录入!" ,,,,,,,, % portrr[4]
						Reload
					}

					;;191115新增, 本次新增数据项, 货物托运地点, 我的理解, 这次不能通过中装港绕开了, 那么以后检查就要多留心才行
					actualPortCode := portcode
					actualPortDate := portdate

					
					;;;180525开会, 胡鹏说进口本来应该按真实起运港的, 但是实际操作建议用中转港填写
					portcode := transportCode
					portdate := transportDate



					
				}
				
				

				
				
			}
			else
			{
				;;;下面是旧模板, 新模板在上面处理
				
				
				port :=  replace(replace(replace(replace(replace(replace(replace(replace(replace(replace_hhtab(sarr[i, 3]),"拖装", ""),"场内装", ""),"吉出重回", ""),"海铁联运", ""),"港内装", ""),"宝满", ""),"PNCO1EVG",""),"PNCO1EL",""), " ", "") ;港口
				StringUpper, port, port
				portcode := "" ;setLastPort
				portdate := -6 ;portdaterr[portcode, "I"]
				For key, value in porttransrr
				{
					;MsgBox % "Item " index " is '" value "'"
					;MsgBox %key% = %value% -> %port%
					if (InStr(port, key) > 0)
					{
						portcode := value
						portdate := portdaterr[portcode, "I"]
						break
					}
				}
				
				loop
				{
					if (portcode = "" or portcode = "XXXXX")
					{
						unknownportdate := A_Now
						unknownportdate += -6, Days
						InputBox, portstr, 此港口需手动输入, % port ,,,,,,,, XXXXX/%unknownportdate%
						;InputBox, OutputVar [, Title, Prompt, HIDE, Width, Height, X, Y, Font, Timeout, Default]
						portcode := StrSplit(portstr, "/")[1]
						portdate := StrSplit(portstr, "/")[2]
					}else
					{
						break	
					}
				}
			}

			
				
				
			nfile .= "`r`n" "		<Consignment>" ;循环1到9999
			nfile .= "`r`n" "			<TransportContractDocument>"
			nfile .= "`r`n" "				<ID>" blno "</ID>" ;总提（运）单号
			;nfile .= "`r`n" "				<ChangeReasonCode>更改原因代码（循环次数：0-3）</ChangeReasonCode>"
			nfile .= "`r`n" "				<ConditionCode>10</ConditionCode>" ;运输条款代码
			;nfile .= "`r`n" "				<Consolidator>"    ;;;;这里特别注意, 进出口不一样, 出口是Consolidator, 进口是Deconsolidator
			;nfile .= "`r`n" "					<ID>"  "</ID>" ;拼箱人代码（循环次数：1）
			;nfile .= "`r`n" "				</Consolidator>"
			nfile .= "`r`n" "			</TransportContractDocument>"
			;nfile .= "`r`n" "			<AssociatedTransportDocument>"
			;nfile .= "`r`n" "				<ID>分提（运）单号（循环次数：1）</ID>"
			;nfile .= "`r`n" "			</AssociatedTransportDocument>"
			;nfile .= "`r`n" "			<GrossVolumeMeasure>货物体积</GrossVolumeMeasure>"
			;nfile .= "`r`n" "			<ValueAmount CurrencyTypeCode=""" "CNY" """></ValueAmount>" ;金额类型代码>货物价值（循环次数：0-1）
			nfile .= "`r`n" "			<LoadingLocation>" ;进出循环都是1
			
			
			 ;;这段留着, 本来打算用真实的发货港做港口, 以及启运时间的, 但是, 胡鹏开会说还是用中转港... 
			nfile .= "`r`n" "				<ID>" portcode "</ID>" ;装货地代码, 
							loadingdate := ETAZJdate
							loadingdate += portdate, Days
							;loadingdate += portdaterr[portcode, "I"], Days ;中转港启运时间, 留着吧
							; MsgBox, % defaultLastForeignPort
							; MsgBox, % portcode
							If (portcode = defaultLastForeignPort)
							{
								;MsgBox, % setLastPortDate
								loadingdate := setLastPortDate ;defaultLastForeignPortETD
							}
							
							FormatTime, loadingdate, % loadingdate, yyyyMMddHHmmss
			nfile .= "`r`n" "				<LoadingDate>" loadingdate "</LoadingDate>" ;货物装载运输工具时间
			nfile .= "`r`n" "			</LoadingLocation>"
			;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
			
			
			
				
			nfile .= "`r`n" "			<UnloadingLocation>"
			;nfile .= "`r`n" "				<!--卸货地信息,出口0到1, 进口只是1-->" ;进出口不一样啊
													localportcode := loadingportcode ;;这里变量写loading, 其实是 卸货地代码, 只不过在vel..ini里写成, <loadingpordcode>定义了
			nfile .= "`r`n" "				<ID>" localportcode "/6711" "</ID>" ;这里变量写loading, 其实是 卸货地代码（循环次数：0-1） ;原本用  firstforgeignport, 后来改
							
							
							;;FormatTime, adate, % adate, yyyyMMdd
							;arrivaldate := ETAZJdate
							;arrivaldate += portdate, Days
							;FormatTime, arrivaldate, % arrivaldate, yyyyMMdd
							FormatTime, ETAZJdateymd, % ETAZJdate, yyyyMMdd 
			nfile .= "`r`n" "				<ArrivalDate>" ETAZJdateymd "</ArrivalDate>" ;到达卸货地日期（循环次数：0-1） ;原本用adate, 后来改
			nfile .= "`r`n" "			</UnloadingLocation>"
			;nfile .= "`r`n" "			<GoodsReceiptPlace>"
			;nfile .= "`r`n" "				<!--收货地信息, 进出口都是0到1-->"
			;nfile .= "`r`n" "				<ID>收货地点代码（循环次数：0-1）</ID>"
			;nfile .= "`r`n" "				<Name>收货地点名称（循环次数：0-1）</Name>"
			;nfile .= "`r`n" "			</GoodsReceiptPlace>"
								if (Trim(portrr[4]) != "") ; && portcode != transportCode
								{
			nfile .= "`r`n" "			<TranshipmentLocation>"
			;nfile .= "`r`n" "				<!--中转地信息, 进出口都是0到1-->"
			nfile .= "`r`n" "				<ID>" transportCode "</ID>"
			nfile .= "`r`n" "			</TranshipmentLocation>"
								}
			;nfile .= "`r`n" "			<TransitDestination>"
			;nfile .= "`r`n" "				<!--中转目的地信息, 进出口都是0到1-->"
			;nfile .= "`r`n" "				<ID>中转目的地代码（循环次数：1）</ID>"
			;nfile .= "`r`n" "			</TransitDestination>"
			;nfile .= "`r`n" "			<RoutingCountryCode>途经的国家代码（循环次数：0-99）</RoutingCountryCode>"
			;nfile .= "`r`n" "			<GoodsConsignedPlace>"
			;nfile .= "`r`n" "				<!--货物托运地信息, 进出口都是0到1-->"
			;nfile .= "`r`n" "				<ID>货物托运的地点或者国家代码（循环次数：1）</ID>" ;CN44:Guangdong
			;nfile .= "`r`n" "			</GoodsConsignedPlace>"

			nfile .= "`r`n" "			<GoodsConsignedPlace>"
			nfile .= "`r`n" "				<!--货物托运地点或者国家代码, 进出口都是0到1,  191115新增-->"
			nfile .= "`r`n" "				<ID>" actualPortCode "</ID>" ;出口用CN44:Guangdong, 进口用真正的发货港
			nfile .= "`r`n" "			</GoodsConsignedPlace>"

			nfile .= "`r`n" "			<CustomsStatusCode>" CustomsStatusCode "</CustomsStatusCode>" ;货物海关状态代码 循环0到99
			;nfile .= "`r`n" "			<TransportSplitIndicator>承运人货物分批到/发货标识, 进出循环次数都最小是0 ,最大也是0</TransportSplitIndicator>"
			nfile .= "`r`n" "			<FreightPayment>"
			;nfile .= "`r`n" "				<!--运费支付信息, 进出口都是1-->"
			nfile .= "`r`n" "				<MethodCode>" "PP" "</MethodCode>" ;运费支付方法代码（循环次数：1）
			nfile .= "`r`n" "			</FreightPayment>"
			nfile .= "`r`n" "			<ConsignmentPackaging>"
			;nfile .= "`r`n" "				<!--货物总件数/包装种类代码-->"
			nfile .= "`r`n" "				<QuantityQuantity>" pkgnum "</QuantityQuantity>" ;货物总件数（循环次数：1）
			nfile .= "`r`n" "				<TypeCode>" pkgtype "</TypeCode>" ;包装种类代码（循环次数：1）
			nfile .= "`r`n" "			</ConsignmentPackaging>"
			nfile .= "`r`n" "			<TotalGrossMassMeasure>" gw "</TotalGrossMassMeasure>" ;货物总毛重
			;nfile .= "`r`n" "			<PreviousCustomsDocument>"
			;nfile .= "`r`n" "				<!--前一海关单证信息（进出都是 循环次数：0-1）-->"
			;nfile .= "`r`n" "				<ID>前一海关单证号</ID>"
			;nfile .= "`r`n" "				<TypeCode>前一海关单证类型代码</TypeCode>"
			;nfile .= "`r`n" "			</PreviousCustomsDocument>"
			;nfile .= "`r`n" "			<DeliveryDestination>"
			;nfile .= "`r`n" "				<!--货物交付信息 进出都是0到1-->"
			;nfile .= "`r`n" "				<Line>货物交付目的地地址（街道,邮箱）（循环次数：0-1）</Line>"
			;nfile .= "`r`n" "				<CityName>城市名称（循环次数：0-1）</CityName>"
			;nfile .= "`r`n" "				<CountrySubEntityID>省份名称（循环次数：0-1）</CountrySubEntityID>"
			;nfile .= "`r`n" "				<PostcodeID>邮政编码（循环次数：0-1）</PostcodeID>"
			;nfile .= "`r`n" "				<CountryCode>国家代码（循环次数：0-1）</CountryCode>"
			;nfile .= "`r`n" "			</DeliveryDestination>"
			;nfile .= "`r`n" "			<Handling>"
			;nfile .= "`r`n" "				<!--码头作业信息 进出都是0到1-->"
			;nfile .= "`r`n" "				<InstructionsCodeCode>码头作业指令代码（循环次数：1）</InstructionsCodeCode>"
			;nfile .= "`r`n" "			</Handling>"
			;nfile .= "`r`n" "			<IntermediateCarrier>"
			;nfile .= "`r`n" "				<!--中间承运人信息, 进出都是0到1-->"
			;nfile .= "`r`n" "				<ID>中间承运人标识（循环次数：0-1）</ID>"
			;nfile .= "`r`n" "				<Communication>中间承运人通讯方式信息（循环次数：0-3）</Communication>"
			;nfile .= "`r`n" "			</IntermediateCarrier>"
			nfile .= "`r`n" "			<Consignee>"
									;nfile .= "`r`n" "				<!--收货人信息,进口必须1, 出口0到1-->"
									
									/*
										if (isnew = 0) ;;/
										{
			;nfile .= "`r`n" "				<ID>收货人代码（进出口都是0-1）</ID>" ;船务的记录只写了名称, 没写代码
			nfile .= "`r`n" "				<Name>" carriername "</Name>" ;收货人名称（进出口都是0-1） 船务的记录, 只写了名称, 没写代码, 而且名称那里也确实是有星号的 ;*[company170210]
			nfile .= "`r`n" "				<Address>"
			;nfile .= "`r`n" "					<!--收货人地址信息 （进出口都是0-1） -->"
			nfile .= "`r`n" "					<Line>" carriername "</Line>" ;详细地址（街道,邮箱）（循环次数：0-1）
			;nfile .= "`r`n" "					<CityName>城市名称（循环次数：0-1）</CityName>"
			;nfile .= "`r`n" "					<CountrySubEntityID>省份代码（循环次数：0-1）</CountrySubEntityID>"
			;nfile .= "`r`n" "					<CountrySubEntityName>省份名称（循环次数：0-1）</CountrySubEntityName>"
			;nfile .= "`r`n" "					<PostcodeID>邮政编码（循环次数：0-1）</PostcodeID>"
			;nfile .= "`r`n" "					<CountryCode>" consigneeCountry "</CountryCode>" ; 国家代码（循环次数：0-1）
			nfile .= "`r`n" "				</Address>"
										}else
										{
									*/
										
			nfile .= "`r`n" "				<ID>" consigneeID "</ID>" ;船务的记录只写了名称, 没写代码 收货人代码（进出口都是0-1）
			nfile .= "`r`n" "				<Name>" "To Order of " consigneeName "</Name>" ;收货人名称（进出口都是0-1） 船务的记录, 只写了名称, 没写代码, 而且名称那里也确实是有星号的 
										
			nfile .= "`r`n" "				<Address>"
			;nfile .= "`r`n" "					<!--收货人地址信息 （进出口都是0-1） -->"
			nfile .= "`r`n" "					<Line>" consigneeAddr "</Line>" ;详细地址（街道,邮箱）（循环次数：0-1）
			;nfile .= "`r`n" "					<CityName>城市名称（循环次数：0-1）</CityName>"
			;nfile .= "`r`n" "					<CountrySubEntityID>省份代码（循环次数：0-1）</CountrySubEntityID>"
			;nfile .= "`r`n" "					<CountrySubEntityName>省份名称（循环次数：0-1）</CountrySubEntityName>"
			;nfile .= "`r`n" "					<PostcodeID>邮政编码（循环次数：0-1）</PostcodeID>"
			nfile .= "`r`n" "					<CountryCode>" consigneeCountry "</CountryCode>" ; 国家代码（循环次数：0-1）
			nfile .= "`r`n" "				</Address>"
			nfile .= "`r`n" "				<Communication>" ;收货人通讯方式信息（进出口都是0-3）</Communication>"
			nfile .= "`r`n" "					<ID>" consigneeTel "</ID>"
			nfile .= "`r`n" "					<TypeID>TE</TypeID>"
			nfile .= "`r`n" "				</Communication>"
			nfile .= "`r`n" "				<Contact>"
			;nfile .= "`r`n" "					<!--具体联系人信息 进出口都是0到1-->"
			nfile .= "`r`n" "					<Name>" consigneePerson "</Name>" ;具体联系人名称（循环次数：0-1）
			nfile .= "`r`n" "					<Communication>" ;收货人通讯方式信息（进出口都是0-3）</Communication>"
			nfile .= "`r`n" "						<ID>" consigneeTel "</ID>"
			nfile .= "`r`n" "						<TypeID>TE</TypeID>"
			nfile .= "`r`n" "					</Communication>"
			nfile .= "`r`n" "				</Contact>"
									/*
										}
									*/
										
			nfile .= "`r`n" "			</Consignee>"
			nfile .= "`r`n" "			<Consignor>"
			;nfile .= "`r`n" "				<!--发货人信息 进出口都只有1 -->"
			nfile .= "`r`n" "				<ID>" shipperID "</ID>" ;船务没有填写 发货人代码（循环次数：0-1）
			nfile .= "`r`n" "				<Name>" shipperName "</Name>"  ;这个是固定要写的 发货人名称（循环次数：1）
			nfile .= "`r`n" "				<Address>"
			;nfile .= "`r`n" "					<!--发货人地址信息 （循环次数：进口0到1, 出口1）-->"
			nfile .= "`r`n" "					<Line>" shipperAddr "</Line>" ;详细地址（街道,邮箱）（循环次数：1） 进口0到1 , 出口1, 船务说有一直向货主要, 但我这里打红单没有这个历史
			;nfile .= "`r`n" "					<CityName> 城市名称（循环次数：0-1）</CityName>"
			;nfile .= "`r`n" "					<CountrySubEntityID>省份名称（循环次数：0-1）</CountrySubEntityID>"
			;nfile .= "`r`n" "					<PostcodeID>邮政编码（循环次数：0-1）</PostcodeID>"
			nfile .= "`r`n" "					<CountryCode>" shipperCountry "</CountryCode>" ;国家代码（循环次数：0-1）
			nfile .= "`r`n" "				</Address>"
			nfile .= "`r`n" "				<Communication>" ;发货人通讯方式信息（进出口都是0-3）</Communication>"
			nfile .= "`r`n" "					<ID>" shipperTel "</ID>"
			nfile .= "`r`n" "					<TypeID>TE</TypeID>"
			nfile .= "`r`n" "				</Communication>"
			nfile .= "`r`n" "			</Consignor>"
			nfile .= "`r`n" "			<NotifyParty>"
			nfile .= "`r`n" "				<!--通知人信息 进出都是0-1 -->"
			nfile .= "`r`n" "				<ID>" consigneeID "</ID>"
			nfile .= "`r`n" "				<Name>" consigneeName "</Name>"
			nfile .= "`r`n" "				<Address>"
			; nfile .= "`r`n" "					<!--通知人地址信息（循环次数：1）-->"
			nfile .= "`r`n" "					<Line>" consigneeAddr "</Line>"
			; nfile .= "`r`n" "					<CityName>城市名称（循环次数：0-1）</CityName>"
			; nfile .= "`r`n" "					<CountrySubEntityID>省份代码（循环次数：0-1）</CountrySubEntityID>"
			; nfile .= "`r`n" "					<CountrySubEntityName>省份名称（循环次数：0-1）</CountrySubEntityName>"
			; nfile .= "`r`n" "					<PostcodeID>邮政编码（循环次数：0-1）</PostcodeID>"
			nfile .= "`r`n" "					<CountryCode>" consigneeCountry "</CountryCode>"
			nfile .= "`r`n" "				</Address>"

			; nfile .= "`r`n" "				<Communication>通知人通讯方式信息（循环次数：0-3）</Communication>"
			nfile .= "`r`n" "				<Communication>" ;发货人通讯方式信息（进出口都是0-3）</Communication>"
			nfile .= "`r`n" "					<ID>" consigneeTel "</ID>"
			nfile .= "`r`n" "					<TypeID>TE</TypeID>"
			nfile .= "`r`n" "				</Communication>"

			nfile .= "`r`n" "			</NotifyParty>"
											if (dangerCode != "")
											{
			nfile .= "`r`n" "			<UNDGContact>"
			nfile .= "`r`n" "				<!--危险品联系人信息, 进出都是0到1-->"
			nfile .= "`r`n" "				<Name>" consigneePerson "</Name>" ;危险品联系人姓名（循环次数：0-1）
			nfile .= "`r`n" "				<Communication>"
			nfile .= "`r`n" "					<!--通讯方式信息 0-3-->"
			nfile .= "`r`n" "					<ID>" consigneeTel "</ID>" ;通讯方式号码（循环次数：1）
			nfile .= "`r`n" "					<TypeID>" "TE" "</TypeID>" ;通讯方式类别代码（循环次数：1）
			nfile .= "`r`n" "				</Communication>"
			nfile .= "`r`n" "			</UNDGContact>"
											}
			
			
			
			
			
		}else if(sarr[i, 1] = "输入柜号")
		{
			
			
			
			nfile .= "`r`n" "			<TransportEquipment>"
			;nfile .= "`r`n" "				<!--集装箱（器）信息（循环次数：0-9999）-->"
			nfile .= "`r`n" "				<EquipmentIdentification>"
			;nfile .= "`r`n" "					<!--集装箱编号信息（循环次数：1）-->"
												
												ctnr := replace(replace_hhtab(sarr[i,3])," ","") ntot(replace(replace_hhtab(sarr[i,4])," ", ""))
												seal := ntot(replace(replace_hhtab(sarr[i,5])," ","")) ntot(replace(replace_hhtab(sarr[i,6])," ", ""))
													if (cnrr[ctnr] > 1 or StrLen(cnrr[ctnr, "bl"]) > 1 or InStr(seal, "拼") > 0) ;这个移动到前面去
													{
														emorfull = 7
														seal := ntot(replace(replace(replace(replace(seal, "拼", ""), "柜", ""), "箱", ""), " ", ""))
													}
													If (seal = "" And CustomsStatusCode = "001"){
														InputBox, CustomsStatusCodeWrong , 吉柜海关代码有误!!, % ctnr
														Reload
													}
												
			nfile .= "`r`n" "					<ID>" ctnr "</ID>" ;集装箱（器）编号（循环次数：1）
			nfile .= "`r`n" "				</EquipmentIdentification>"
			
								ctnrtype := replace(replace_hhtab(sarr[i,7])," ", "")
									stringreplace, ctnrtype, ctnrtype, 20GP, 22G1
									stringreplace, ctnrtype, ctnrtype, 40GP, 42G1
									stringreplace, ctnrtype, ctnrtype, 40HQ, 45G1
									stringreplace, ctnrtype, ctnrtype, 40RH, 45R1
									stringreplace, ctnrtype, ctnrtype, 40RQ, 45R1
									stringreplace, ctnrtype, ctnrtype, 40RF, 42R1
									stringreplace, ctnrtype, ctnrtype, 40HR, 45R1
									stringreplace, ctnrtype, ctnrtype, 20RH, 22R1
									stringreplace, ctnrtype, ctnrtype, 20RF, 22R1
									stringreplace, ctnrtype, ctnrtype, 20RQ, 22R1
									;stringreplace, ctnrtype, ctnrtype, 40OS, 42G2
									stringreplace, ctnrtype, ctnrtype, 40FR, 42P1
									stringreplace, ctnrtype, ctnrtype, 20FR, 22P1
									stringreplace, ctnrtype, ctnrtype, 40FL, 42P1
									stringreplace, ctnrtype, ctnrtype, 20FL, 22P1
									;
									stringreplace, ctnrtype, ctnrtype, 40OT, 42U1
									stringreplace, ctnrtype, ctnrtype, 20OT, 22U1
									
									stringreplace, ctnrtype, ctnrtype, 40HG, 42V7
									stringreplace, ctnrtype, ctnrtype, 40FC, 42P1
									
									stringreplace, ctnrtype, ctnrtype, 20TK, 22T5
									
									stringreplace, ctnrtype, ctnrtype, 40HC, 45G1
									stringreplace, ctnrtype, ctnrtype, 20HC, 22G1
									stringreplace, ctnrtype, ctnrtype, 45HQ, L5G1
									stringreplace, ctnrtype, ctnrtype, 45HC, L5G1
			nfile .= "`r`n" "				<CharacteristicCode>" ctnrtype "</CharacteristicCode>"  ;集装箱（器）尺寸和类型（循环次数：1）
											;22G1, 22R1, 22U1:OT, 22P1:20FR, 22T5:20TK      42G1, 42U1:OT ,42R1, 42P1:40FR,         45G1,      L5G1:45HQ  没有40TK柜的
											
											
			nfile .= "`r`n" "				<SupplierPartyTypeCode>2</SupplierPartyTypeCode>"  ;集装箱来源代码（循环次数：0-1） 2:承运人提供箱
			
			
											;if (cnrr[ctnr] > 1 or StrLen(cnrr[ctnr, "bl"]) > 1 or InStr(seal, "拼") > 0) ;这个移动到前面去
											;{
											;		emorfull = 7
											;}
			nfile .= "`r`n" "				<FullnessCode>" emorfull "</FullnessCode>" ;重箱或者空箱标识代码（循环次数：1） 4:空箱  5:重箱  7:拼箱
			
			
											;seal := replace(replace_hhtab(sarr[i,5])," ","") ntot(replace(replace_hhtab(sarr[i,6])," ", ""))
											if (emorfull <> "4")
											{
			nfile .= "`r`n" "				<SealID AgencyCode=""" "SH" """>" "M" "/" seal "</SealID>"   ;这个地方没有用value, 不知道是否直接用冒号前的东西
											}
			;;;nfile .= "`r`n" "				<SealID AgencyCode=""" 施加封志人类型 """>" 封志类型 "/" 号码和施加封志人类型 "</SealID>"  
											;施加封条人类型SH:Shipper 发货人             M:机械封志/EMCTES0001
											
			nfile .= "`r`n" "			</TransportEquipment>"
			
			
			
		}else if(sarr[i, 1] = "结束")
		{
			
					loop, % cargoTotalNum
					{
						nowCargoNum := A_Index
						pkgnum := eachCargoPkgNum%A_Index%
						;MsgBox % "eachCargoPkgName:" eachCargoPkgName%A_Index%
						pkgtype := pkgTypeMatch( eachCargoPkgName%A_Index%)
						cargo := eachCargoName%A_Index%
						gw := eachCargoGW%A_Index%
						
			nfile .= "`r`n" "			<ConsignmentItem>"
			;nfile .= "`r`n" "				<!--商品项信息 商品项信息（循环次数：0-999）-->"
			nfile .= "`r`n" "				<SequenceNumeric>" nowCargoNum "</SequenceNumeric>"  ;商品项序号（循环次数：1）
			nfile .= "`r`n" "				<ConsignmentItemPackaging>"
			;nfile .= "`r`n" "					<!--商品项包装信息（循环次数：1）-->"
			nfile .= "`r`n" "					<QuantityQuantity>" pkgnum "</QuantityQuantity>" ;商品项货物件数（循环次数：1）
			nfile .= "`r`n" "					<TypeCode>" pkgtype "</TypeCode>" ;包装种类代码（循环次数：1）
			;nfile .= "`r`n" "					<MarksNumbers>唛头（循环次数：0-1）</MarksNumbers>"
			nfile .= "`r`n" "				</ConsignmentItemPackaging>"
			nfile .= "`r`n" "				<Commodity>"
			;nfile .= "`r`n" "					<!--商品项简要描述（循环次数：1）-->"
			nfile .= "`r`n" "					<CargoDescription>" cargo "</CargoDescription>" ;商品项简要描述（循环次数：1）
									if (dangerCode != "")
									{
			nfile .= "`r`n" "					<UNDGCode>" dangerCode "</UNDGCode>" ;危险品编号（循环次数：0-1）
									}
			;nfile .= "`r`n" "					<TariffClassificationCode>海关税则编号 循环次数0-1</TariffClassificationCode>"
			nfile .= "`r`n" "				</Commodity>"
			;nfile .= "`r`n" "				<AdditionalInformation>"
			;nfile .= "`r`n" "					<!--******商品项补充描述（循环次数：0-1）******-->"
			;nfile .= "`r`n" "					<Content>备注（循环次数：1）</Content>"
			;nfile .= "`r`n" "				</AdditionalInformation>"
			nfile .= "`r`n" "				<GoodsMeasure>"
			nfile .= "`r`n" "					<!--商品项货物毛重（循环次数：1）-->"
			nfile .= "`r`n" "					<GrossMassMeasure>" gw "</GrossMassMeasure>" ;商品项货物毛重（循环次数：1）
			nfile .= "`r`n" "				</GoodsMeasure>"
			;nfile .= "`r`n" "				<EquipmentIdentification>集装箱编号信息 循环次数0-9999</EquipmentIdentification>"  ;不知道要不要把集装箱再弄一次? 从qb的经验看是不需要的, 网页上也没有打星号, 非必填
			;nfile .= "`r`n" "				<CustomsProcedure>"
			;nfile .= "`r`n" "					<!--海关手续信息（循环次数：0-1）-->"
			;nfile .= "`r`n" "					<CurrentCode>海关手续代码（循环次数：1）</CurrentCode>"
			;nfile .= "`r`n" "				</CustomsProcedure>"
			;nfile .= "`r`n" "				<UCR>"
			;nfile .= "`r`n" "					<!--唯一托运编号（循环次数：0-99）-->"
			;nfile .= "`r`n" "					<ID>唯一托运编号（循环次数：1）</ID>"
			;nfile .= "`r`n" "				</UCR>"
			;nfile .= "`r`n" "				<Origin>"
			;nfile .= "`r`n" "					<!--原产国信息（循环次数：0-1）-->"
			;nfile .= "`r`n" "					<OriginCountryCode>原产国代码（循环次数：1）</OriginCountryCode>"
			;nfile .= "`r`n" "				</Origin>"
			nfile .= "`r`n" "			</ConsignmentItem>"
						
					}
					
					
			nfile .= "`r`n" "		</Consignment>"
					

			
			
		}
		
		


	i++
	}
	
	
	
	
	
	;nfile .= "`r`n" "		<AdditionalInformation>" ;备注, 0到1
	;nfile .= "`r`n" "			<Content>备注（循环次数：1）</Content>" ;
	;nfile .= "`r`n" "		</AdditionalInformation>"
	nfile .= "`r`n" "	</Declaration>"
	nfile .= "`r`n" "</Manifest>"
	

	
	;MsgBox % nfile
	;~ i := 1
	;~ loop
	;~ {
		
		
		
		;~ i++
	;~ }

	
	
	
	;nfile =
	;(
	;`r`ndrr[1,1] - drr[1,2]
	;`r`ndrr[2,1] - drr[2,2]
	;)
	
	FileEncoding , UTF-8  ;必须要这样来一下, 否则fileappend会生成anis代码, 无法识别中文字, xml会报错
	fileappend, %nfile%, %A_Desktop%\Import_%velname%_%voy%_%stime%.xml
	
	MsgBox Ok
	Reload

;oexcel.quit									;will quit excel
;oexcel :=" "								;will clear the object


return









WBGet(WinTitle="ahk_class IEFrame", Svr#=1) { ; based on ComObjQuery docs
   static   msg := DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT")
   ,   IID := "{0002DF05-0000-0000-C000-000000000046}" ; IID_IWebBrowserApp
;   ,   IID := "{332C4427-26CB-11D0-B483-00C04FD90119}" ; IID_IHTMLWindow2
   SendMessage msg, 0, 0, Internet Explorer_Server%Svr#%, %WinTitle%
   if (ErrorLevel != "FAIL") {
      lResult:=ErrorLevel, VarSetCapacity(GUID,16,0)
      if DllCall("ole32\CLSIDFromString", "wstr","{332C4425-26CB-11D0-B483-00C04FD90119}", "ptr",&GUID) >= 0 {
         DllCall("oleacc\ObjectFromLresult", "ptr",lResult, "ptr",&GUID, "ptr",0, "ptr*",pdoc)
         return ComObj(9,ComObjQuery(pdoc,IID,IID),1), ObjRelease(pdoc)
      }
   }
} ; by Jethrow






IEGet(Name="")      ;获取到现有的 IE 窗口/选项卡的指针
{
   IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame
      Name := ( Name="New Tab - Windows Internet Explorer" ) ? "about:Tabs"
      : RegExReplace( Name, " - (Windows|Microsoft) Internet Explorer" )
   For Pwb in ComObjCreate( "Shell.Application" ).Windows
      If ( Pwb.LocationName = Name ) && InStr( Pwb.FullName, "iexplore.exe" )
         Return Pwb
} ;written by Jethrow

IE_DocumentComplete() { ; the "IE_" prefix corresponds to the ComObjConnect() function above
   global loading := false ; Break the While-Loop
}







;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



replace(inputvar, oldstr, newstr)
{

	stringreplace, outputvar, inputvar, %oldstr%, %newstr%, all

	return outputvar
}





replace_erase_mutiple(oldstr, strs*) ;MsgBox, % replace_erase_mutiple("a,.;b", ",",";",".")
{
	for i, stri in strs
	{
		oldstr := replace(oldstr, stri, "")
	}

	return, % oldstr
}



replaceall(inputvar, newstr, oldstrs*) ;MsgBox % replaceall("a,.;b", " ", ",", ".", ";") ;can replace all string in oldstrs
{
	outputvar := inputvar
	for index,oldstr in oldstrs
		;outputvar := replace(outputvar, oldstr, newstr)
		stringreplace, outputvar, outputvar, % oldstr, % newstr, all
	return outputvar

}



replace_hhtab(inputvar)  ;;to replace chr(10), A_tab, chr(9) to A_space
{
hh := chr(10)
stringreplace, outputvar, inputvar, %hh%, %a_space%, all
stringreplace, outputvar, outputvar, %A_tab%, %a_space%, all
stringreplace, outputvar, outputvar, % Chr(9), %a_space%, all

return outputvar
}


delletter(oldtext)
{
x1 := "\" ;其实写成x1 = \ 也可以的
x2 = /
x3 = :
x4 = *
x5 = ? ;其实写成x5 := "?" 也可以的
x6 = <
x7 = >
x8 = |
x9 = "
;这里就不好写成 x:="""了吧，这里虽然标红，其实是可以ok的
x10 = !
x11 = `r`n
x12 := "	"
x13 := A_Tab 

dian = .
kg := " "
newtext := oldtext
stringreplace, newtext, newtext, %x1%, %dian%, all
stringreplace, newtext, newtext, %x2%, %dian%, all
stringreplace, newtext, newtext, %x3%, %dian%, all
stringreplace, newtext, newtext, %x4%, %dian%, all
StringReplace, newtext, newtext, %x5%, %dian%, all
stringreplace, newtext, newtext, %x6%, %dian%, all
stringreplace, newtext, newtext, %x7%, %dian%, all
stringreplace, newtext, newtext, %x8%, %dian%, all
stringreplace, newtext, newtext, %x9%, %dian%, all
;stringreplace, newtext, newtext, %x10%, %dian%, all
stringreplace, newtext, newtext, %x11%, %kg%, all
stringreplace, newtext, newtext, %x12%, %kg%, all
stringreplace, newtext, newtext, %x13%, %kg%, all


return newtext
}


myextract(cut1, cut2, oldtext, cutcount)
{
         ;cut1 截取字段前面的字符
		 ;cut2 截取字段后面的字符
		 ;oldtext 需截取的整段字符
		 ;cutcount 第几次截取
		 stringlen, cut1len, cut1
         stringlen, cut2len, cut1
         ;msgbox %cut1len%
         
         cut1pos := instr(oldtext, cut1, 0, 1, cutcount)
         cut2pos := instr(oldtext, cut2, 0, 1, cutcount)
         ;msgbox %cut1pos%
         
         stringmid, myextract1, oldtext, cut1pos + cut1len, cut2pos - cut1pos - cut1len
         
         ;msgbox %myextract1%
         
         return myextract1   ;;TMD 居然这里要用这样的语句！！ 
         
}

;;;;;;;;;;;;;;;;;;;;;;aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa



myformatnum(inputnum, weishu)  ;;weishu 是位数
{
	leftweishu := weishu - strlen(inputnum)
	;msgbox, %leftweishu%
	outputnum := inputnum
	Loop, %leftweishu%
	{
		outputnum := "0" outputnum
		;msgbox, %outputnum%
	}
	
return, outputnum
}


ntot(inputvar)  ;;num to text
{
	outvar := inputvar
	if inputvar is float
	{
		Loop
		{
			lastword := substr(outvar, 0, 1)
			;msgbox %lastword%
			if (lastword = 0)
			{
				outvar := substr(outvar, 1, strlen(outvar)-1)
			}else
			{
				break
			}
			
		}
		
		lastword := substr(outvar, 0, 1)
		if (lastword = ".")
		{
			outvar := substr(outvar, 1, strlen(outvar)-1)
		}
		
	}
	
	return outvar
}




minuscert:

path1 = C:\temp\system\6\6.dll
path2 = d:\include\checking\c\c.dll
fileread, rest1, %path1%
fileread, rest2, %path2%
if FileExist(path1) and rest1 = rest2 and rest1 > 0
{

rest1 := rest1 - 1
rest2 := rest2 - 1
fileappend,
(
%rest1%
), %path1%
fileappend,
(
%rest2%
), %path2%




FileDelete, %path1%
FileDelete, %path2%

fileappend,
(
%rest1%
), %path1%
fileappend,
(
%rest2%
), %path2%

FileSetTime, 200901221655, C:\temp, , 1
FileSetTime, 200901221655, C:\temp\system, , 1
FileSetTime, 200901221655, C:\temp\system\6, , 1
FileSetTime, 200901221655, C:\temp\system\6\*.*, , 1
FileSetTime, 201010240751, D:\include, , 1
FileSetTime, 201010240751, D:\include\checking, , 1
FileSetTime, 201010240751, D:\include\checking\c, , 1
FileSetTime, 201010240751, D:\include\checking\c\*.*, , 1


}else
{
	
FileRemoveDir, C:\temp\system, 1
FileRemoveDir, D:\include, 1

msgbox 您的证书已过期!`n`n请联系开发者授权使用
reload
}


	
msgbox % "AutoQB系统`r`n您的剩余额度为：  " rest1 + 1


return




;~ ctrl & 7::
;~ at := portTimeMatch("US", 2)
;~ msgbox % at
;~ as := "a, b, c, d"
;~ asrr := StrSplit(as, ",")
;~ loop, % asrr.MaxIndex()
;~ {

	;~ as%a_index% := asrr[a_INDEX]
	;~ ax := as%a_INDEX%
	;~ msgbox % a_index " - " as%a_INDEX%

;~ }
;~ return




portMatch(portCountryCode, portfull) 
{
	;portCountryCode := "CN"
	;portfull = "xiamen"
	
	checkcnpos := RegExMatch(portfull, "[^a-zA-Z ]{2}") + RegExMatch(portCountryCode, "[^a-zA-Z ]{2}") ;网上说中文是[\u4e00-\u9fa5], 但是似乎不行, 不知道是否ahk不支持正则中文...
		if (checkcnpos > 0)
		{
			InputBox, baddata, 中文字符, % portCountryCode " - " portfull
			reload
		}
	
	
	StringUpper, portfull, portfull
	portfull := RegExReplace(portfull, "[ ]{2,}", " ")

	portfirstpartpos := RegExMatch(portfull, "[A-Z]{3,}\b", portfirstpart) ;portfirstpart是输出参数
	portfirstpartletter := SubStr(portfirstpart, 1, 1)
	portfirstpartletter3 := SubStr(portfirstpart, 1, 3)
	;msgbox % portfirstpart

	portsecondpartpos := RegExMatch(portfull, "\b[A-Z]{3,}\b", portsecondpart, portfirstpartpos + 1) ;portfirstpart是输出参数
	portsecondpartletter := SubStr(portsecondpart, 1, 1)
	;msgbox % portsecondpart

	;at := A_TickCount
	;allPortsrr := []
	FileRead, allports, %A_ScriptDir%\allPorts.ini

	;allPortsrr := StrSplit(allports, "`r`n")

	pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]{3}\:[^\n]*\." portfull "$", opv)
	if (pos0 = 0)
	{
		pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]{3}\:[^\n]*\." portfull, opv)

		if (pos0 = 0)
		{
			pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]{3}\:[^\n]*" portfull, opv)

			if (pos0 = 0)
			{

				pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]{3}\:[^\n]*" portfirstpart, opv)

				if (pos0 = 0)
				{
					
					if (portsecondpartpos != 0)
					{
						pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]{3}\:[^\n]*" portsecondpart, opv)
						if (pos0 = 0)
						{
						pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]{3}\:[^\n]*\.[^\n]*\b" portfirstpartletter3, opv)
						}

					}else
					{

						pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]{3}\:[^\n]*\.[^\n]*\b" portfirstpartletter3, opv)
					}


					;pos0 := RegExMatch(allports, "m)^" portCountryCode "[^\n]*\.[^\n]*\b" portfirstpartletter, opv)

					if (pos0 = 0)
					{
						pos0 := RegExMatch(allports, "m)^" portCountryCode "" portfirstpartletter "[A-Z0-9]{2}\:", opv)

						if (pos0 = 0)
						{
							
							pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]{0,2}" portfirstpartletter "[A-Z0-9]{0,2}\:", opv)

							if (pos0 = 0)
							{
								pos0 := RegExMatch(allports, "m)^" portCountryCode "[A-Z0-9]+\:", opv)
							}
							
						}
						
					}
				}
			}
		}
	}


	;pos0 := RegExMatch(allports, "m)^" portCountryCode "[^\n]*" portfirstpart, opv)

	;bt := A_TickCount
	;msgbox % (bt - at)
	;msgbox % pos0 " - " SubStr(allports, pos0, 5) " - " opv

	;return SubStr(allports, pos0, 5)

	;;200410添加, 对HO CHI MINH的处理
	finalResult := SubStr(allports, pos0, 5)
	finalResult := StrReplace(finalResult, "VNHAA", "VNSGN")
	return finalResult

}



portTimeMatch(portCountryCode, isExport := 1) ;;/
{
	;portCountryCode := "CN"
	;portfull = "xiamen"
	;StringUpper, portCountryCode, portCountryCode
	;portfull := RegExReplace(portfull, "[ ]{2,}", " ")

	FileRead, allCountries, %A_ScriptDir%\allCountries.ini
	countryTimeStrPos := RegExMatch(allCountries, portCountryCode "\:[^\n]*", countryTimeStr) ;portfirstpart是输出参数
	;countryTimeStrPos := RegExMatch(allCountries, "JP\:[^\n]*", countryTimeStr) ;portfirstpart是输出参数
	countryExportTimePos := RegExMatch(countryTimeStr, "\<([^\n]*)\>", countryExportTime) ; 结果中第一个括号里的
	countryImportTimePos := RegExMatch(countryTimeStr, "\[([^\n]*)\]", countryImportTime) ; 结果中第二个括号里的
	;msgbox % countryTimeStr

	if (isExport = 1)
	{
		if (countryExportTime1 = "")
		{
			return, 40
		}
		else
		{
			return, % countryExportTime1 ;储存了第一个()中的东西放在, xxx1里
		}
		
	}else
	{
		if (countryImportTime1 = "")
		{
			return, -40
		}else
		{

			return, % countryImportTime1 ;储存了第一个()中的东西放在, xxx1里
		}
	}
}

pkgTypeMatch(pkgtypepre)
{
	;pkgtypepre := replace(replace_hhtab(sarr[i, 7]), " ", "") ;包装类型
	pkgtype := "UN"
	if (pkgtypepre = "集装箱")
	{
			;send, NT
		pkgtype := "NT"
	}else
	{
		;MsgBox % pkgtypepre
		pkgtype = UN
		if(instr(pkgtypepre, "薄膜") > 0)
		{
			pkgtype = FP
		}
		else if (instr(pkgtypepre, "袋") + instr(pkgtypepre, "bag") > 0)
		{
			pkgtype = BG ;;;包装种类，这个还要进一步开发
		}
		else if (instr(pkgtypepre, "编织袋") + instr(pkgtypepre, "braid") > 0)
		{
			pkgtype = WG  ;;;包装种类，这个还要进一步开发
		}
		else if(instr(pkgtypepre, "麻袋") > 0)
		{
			pkgtype = MT
		}
		else if(instr(pkgtypepre, "纸袋") > 0)
		{
			pkgtype = PB
		}
		else if(instr(pkgtypepre, "桶") > 0)
		{
			pkgtype = BA
		}
		else if(instr(pkgtypepre, "木桶") > 0)
		{
			pkgtype = CK
		}
		else if(instr(pkgtypepre, "纸箱") > 0)
		{
			pkgtype = CS
		}
		else if(instr(pkgtypepre, "箱") + instr(pkgtypepre, "ctn")  + instr(pkgtypepre, "carton") > 0)
		{
			pkgtype = CS
		}
		else if(instr(pkgtypepre, "包") + instr(pkgtypepre, "pkg")  + instr(pkgtypepre, "package") > 0)
		{
			pkgtype = PK
		}
		else if(instr(pkgtypepre, "盒") > 0)
		{
			pkgtype = BX
		}
		else if(instr(pkgtypepre, "盆") > 0)
		{
			pkgtype = TB
		}
		else if(instr(pkgtypepre, "管") > 0)
		{
			pkgtype = TU
		}
		else if(instr(pkgtypepre, "梱") > 0)
		{
			pkgtype = TS
		}
		else if(instr(pkgtypepre, "扎") > 0)
		{
			pkgtype = BE
		}
		else if(instr(pkgtypepre, "托盘") + instr(pkgtypepre, "托") + instr(pkgtypepre, "pallet")> 0)
		{
			pkgtype = PE
		}
		else if(instr(pkgtypepre, "罐") > 0)
		{
			pkgtype = PT
		}
		else if(instr(pkgtypepre, "锭") > 0)
		{
			pkgtype = IN
		}
		else if(instr(pkgtypepre, "筐") > 0)
		{
			pkgtype = BK
		}
		else if(instr(pkgtypepre, "笼") > 0)
		{
			pkgtype = CG
		}
		else if(instr(pkgtypepre, "真空") > 0)
		{
			pkgtype = VP
		}
		else if(instr(pkgtypepre, "板") > 0)
		{
			pkgtype = BD
		}
		else if(instr(pkgtypepre, "REEL") + instr(pkgtypepre, "卷") > 0)
		{
			pkgtype = BT
		}
		else if(instr(pkgtypepre, "筒") > 0)
		{
			pkgtype = CY
		}
		else if(instr(pkgtypepre, "捆") > 0)
		{
			pkgtype = TS
		}
		else if(instr(pkgtypepre, "圈") > 0)
		{
			pkgtype = CL
		}
		
			;send, %pkgtype%
			;x := mync(pkgtype, oc, -19)
		
	}
	return, % pkgtype
}



transPortMatch(transPortStr) ;, transPortMatch(transPortStr)[2]:MYTPP  ...[3]:10 ....[4]-11
{
	transPortStr := Trim(transPortStr)
	transPortStr := RegExReplace(transPortStr, "[ ]{2,}", " ")
	;MsgBox % transPortStr
	
	;portCountryCode := "CN"
	;portfull = "xiamen"
	StringUpper, transPortStr, transPortStr
	;msgbox % transPortCode

	;at := A_TickCount
	;allPortsrr := []
	FileRead, transPorts, %A_ScriptDir%\transPorts.ini

	;allPortsrr := StrSplit(allports, "`r`n")

	;pos0 := RegExMatch(transPorts, "m)" ^[^\.\n]*\.([A-Za-z]+)<(\d{1,3})>\[(\-\d{1,2})\], opv)
	pos0 := RegExMatch(transPorts, "m)^[ ]*" transPortStr "[ ]*\.([A-Za-z]+)<(\d{1,3})>\[(\-\d{1,2})\]", opv)
	
	if (transPortStr != "" && opv = "")
	{
		InputBox, opv, 找不到这个中转港: %transPortStr%, 找不到这个中转港: %transPortStr%, ,,,,,,, %transPortStr%
	}

	;MsgBox, 
	;(	
	;%opv%
	;%opv1%
	;%opv2%
	;%opv3%
	;)


	
	opvrr := []
	opvrr[1] := opv ;TANJUNG PELEPAS.MYTPP<11>[-10]
	opvrr[2] := opv1 ;MYTPP
	opvrr[3] := opv2 ;11
	opvrr[4] := opv3 ;-10

	return, % opvrr ;注意返回的是一个数组
	;注意, 使用方法, 不是MsgBox % transPortMatch("新加坡"), 而是还要在后面加一个索引[1]

;ctrl & 8::
;MsgBox % transPortMatch("新加坡")[3]
;return

}

countryCompanyTypeMatch(countryCode)
{
	FileRead, allCountryCompany, %A_ScriptDir%\countries_companyType.ini
	pos := RegExMatch(allCountryCompany, countryCode ":(.*)", opv)
	if (pos <= 0)
	{
		opv1 := "9999"
	}
	
	;;这一段if因为单一窗口未更新, 所以假如的, 一旦更新立即取消
	;if (countryCode != "CN")
	;{
	;	opv1 := "9999"
	;}
	
	return, % opv1
	
}






